Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strtotime('today') returning incorrect time?

I am trying to create a select list starting from the current date of the user. I want it so that it is set to midnight in unix timestamp format.

This is all I'm doing:

$today = strtotime('today');
echo $today;

This is my result:

1333144800

which is: Fri, 30 Mar 2012 22:00:00 GMT according to Epoch Converter (incorrect by a couple hours.)

like image 869
Johnathan Au Avatar asked Mar 31 '12 16:03

Johnathan Au


People also ask

Why is Strtotime return false?

If the date string isn't understood by strtotime() then it will return false. When this happens you can try a few things to force strtotime() to parse the date correctly. Sometimes it's something as simple as swapping the slashes for dashes, which forces strtotime() to parse the date in a different way.

What does Strtotime return in PHP?

The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.

How do I change Strtotime?

Code for converting a string to dateTime$date = strtotime ( $input ); echo date ( 'd/M/Y h:i:s' , $date );


1 Answers

If you want strtotime() to return a timestamp relative to UTC (00:00:00 UTC instead of e.g. 00:00:00 UTC+2, if your system is set to a timezone with an offset of 2 hours against UTC/GMT), you need to specify that:

$today = strtotime('today UTC');
like image 108
Niko Avatar answered Oct 04 '22 14:10

Niko