Given a timestamp, what would be the most elegant solution to round that date up to the nearest midnight of the next day?
For example 1374246685
(19/07/13 10:11:25) would be rounded to 1374296400
(20/07/13 00:00:00).
Given a timestamp, what would be the most elegant solution to round that date up to the nearest midnight of the next day?
For example 1374246685
(19/07/13 10:11:25) would be rounded to 1374296400
(20/07/13 00:00:00).
DateTime can do this nicely:-
$midnight = (new \DateTime())->setTimestamp(1374246685)->modify('tomorrow');
PHP version >= 5.4 only though.
Otherwise it would be:-
$midnight = new \DateTime();
$midnight->setTimestamp(1374246685)->modify('tomorrow')->setTime(0, 0);
Even more elegant than Pete's solution:
$tomorrowMidnight = strtotime('tomorrow');
Check out http://www.php.net/manual/en/datetime.formats.relative.php - you can do lots of fancy stuff with that :)