I have a Unix timestamp like this:
$timestamp=1330581600
How do I get the beginning of the day and the end of the day for that timestamp?
e.g.
$beginOfDay = Start of Timestamp's Day
$endOfDay = End of Timestamp's Day
I tried this:
$endOfDay = $timestamp + (60 * 60 * 23);
But I don’t think it’ll work because the timestamp itself isn’t the exact beginning of the day.
strtotime can be used to to quickly chop off the hour/minutes/seconds
DateTime can also be used, though requires a few extra steps to get from a long timestamp
With the addition of extended time in PHP7, there is potential to miss a second if using
$now <= $endchecking with this.Using
$now < $nextStartchecking would avoid that gap, in addition to the oddities around subtracting seconds and daylight savings in PHP’s time handling.