This is a quick post where I am sharing a couple of functions to calculate start of a given day and end of the day for a given timezone
Start of the day
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/** * start time for the date for a specific timezone * * @param $tz * @return string */ function StartOfDay($tz) { $dateNow = new \DateTime('now',new \DateTimeZone($tz)); $dateNow->modify('today'); return $dateNow->format('Y-m-d H:i:s'); } // Usage $date = StartOfDay("Australia/Melbourne"); |
End of the day
1 2 3 4 5 6 7 8 9 10 11 12 |
/** * End time for today for a specific timezone * * @param $tz * @return string */ public static function EndOfDay($tz) { $dateNow = new \DateTime('now',new \DateTimeZone($tz)); $dateNow->modify('tomorrow'); $dateNow->modify('1 second ago'); return $dateNow->format('Y-m-d H:i:s'); } |
1 2 |
// Usage $date = EndOfDay("Australia/Melbourne"); |
You can play with these function and can adjust as per your requirement. Let me know if you see any issues with these.
I hope that this post will help you out in one way or another,
Cheers
Leave a Reply