Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strtotime - a second before midnight

Tags:

php

I attempted this:

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

But I think PHP can't interpret that for some reason as it returned empty. I tried this:

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

The above worked but I need it to be a second before midnight i.e. the last second of the day. How can I get strtotime to return this without changing the 6 Mar, 2011 part?

like image 366
Abs Avatar asked Mar 06 '11 17:03

Abs


2 Answers

Hope this helps. I used this and it gives todays timestamp just before midnight. Counter intuitive.

$today_timestamp =  strtotime('tomorrow - 1 second');
like image 57
DBL Avatar answered Oct 13 '22 08:10

DBL


It works for me if I use March 6, 2011 23:59:59. Any chance of changing the input format?

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

$date_string = strtotime('7 Mar, 2011 midnight') - 1;
like image 21
Pekka Avatar answered Oct 13 '22 07:10

Pekka