How would I go about getting a timestamp in php for today at midnight. Say it's monday 5PM and I want the Timestamp for Monday(today) at midnight(12 am) which already has happened.
This question is tagged with
~ Asked on 2012-10-29 21:16:31
$timestamp = strtotime('today midnight');
You might want to take a look what PHP has to offer: http://php.net/datetime
~ Answered on 2012-10-29 21:20:04
I think that you should use the new PHP DateTime object as it has no issues doing dates beyond the 32 bit restrictions that strtotime() has. Here's an example of how you would get today's date at midnight.
$today = new DateTime(); $today->setTime(0,0);
Or if you're using PHP 5.4 or later you can do it this way:
$today = (new DateTime())->setTime(0,0);
Then you can use the
echo $today->format('Y-m-d'); to get the format you want your object output as.
~ Answered on 2014-03-20 14:16:07