Strtotime - second to midnight

I tried to do this:

$date_string = strtotime('6 Mar, 2011 23:59:59'); 

But I think PHP cannot interpret this for some reason, since it returned empty. I tried this:

 $date_string = strtotime('6 Mar, 2011 midnight'); 

The above, but I need him to be second until midnight, that is, the last second of the day. How can I get strtotime to return this without changing part of March 6, 2011?

+7
source share
4 answers

This works for me if I use March 6, 2011 23:59:59 . Is there a chance to change the input format?

Other than that, you could, of course, subtract 1 second from the timestamp. Please note that you need to use March 7th:

 $date_string = strtotime('7 Mar, 2011 midnight') - 1; 
+10
source

Hope this helps. I used this and it gives today's timestamp until midnight. The counter is intuitive.

 $today_timestamp = strtotime('tomorrow - 1 second'); 
+11
source

Why not use mktime ?

 mktime(23,59,59,3,6,2011); 
+2
source

If you are using PHP 5.3 or higher, you can use the DateTime class.

The createFromFormat function allows you to manually specify how to parse a date input string.

 $date = '6 Mar, 2011 23:59:59'; $timestamp = DateTime::createFromFormat('d M, YH:i:s', $date)->getTimestamp(); 
+2
source

All Articles