strtotime('today') returning incorrect time?

Johnathan Au picture Johnathan Au · Mar 31, 2012 · Viewed 42.7k times · Source

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.)

Answer

Niko picture Niko · Mar 31, 2012

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');