<?php
header('Content-Type: text/plain');
$time = '0000-00-00 00:00:00';
echo $time . PHP_EOL . PHP_EOL;
$time = strtotime($time);
echo $time . PHP_EOL . PHP_EOL;
On our development server, the second $time outputs nothing. A test with var_dump() reveals its value to be false. Which is fine. On a live server, I get 943920000. A test with var_dump() shows that this is an integer.
Why?
Apparently it is fairly common for dates of zero to come up as 30 November 1999. Why? And why on some servers and not on others?
Reading the PHP Manual page for
strtotime(), we get the following:Therefore it follows that on one of your servers, the call to
strtotime()is failing.So why would it fail? The answer to that is also on the same manual page:
So it seems to me that your one server doesn’t have it’s timezone locale configured correctly.
All that said and done, I would suggest not using
strtotime()for stuff like this, if possible. It is a bit of a clunky old function, and the newer PHP datetime library provides much better/cleaner functionality. You can create a datetime object using it as follows:hope that helps.