I have a document with a "birthday" field and this can also have a value lower that 01-01-1970. How can I handle this? E.g.
{....
'birthday' => newMongoDate(strtotime('31/10/1968')),
....
}
This creates a "birthday" value: "1/1/1970 12:00:00 AM" (DateTime)
What version of PHP are you running? I'm guessing PHP < 5.1 on windows?
strtotime()
should have a date range of Fri, 13 Dec 1901 20:45:54 GMT and Tue, 19 Jan 2038 03:14:07 GMT with PHP 5.1 and later.For PHP 5.2 and greater you could use:
or,
That is because the UNIX timestamp goes from 1970 ( http://php.net/manual/en/function.strtotime.php ) which is where
strototime
counts from. Even thoughstrtotime
can go from 1901 it is noted that:So it is highly likely you are running into the problem where your system simply does not support a date before the epoch.
You can do as @nick says and use
DateTime()
instead, more specifically its owntimestamp
function: http://www.php.net/manual/en/datetime.gettimestamp.phpOnly option that i can think of is to use nested Date object something like
of Course there would be issues but this is the only option for windows users.