php - Parsing date error -
i have strange error dont understand. reason, dates not parsed.
the code:
$day = strtotime($_get['d']."-".$_get['m']."-".$_get['y']); $datetimezone = new datetimezone("europe/prague"); $datetime = new datetime($day, $datetimezone); $offset = ($datetimezone->getoffset($datetime))/3600;
now weird thing is.... if pass in numbers, works, doesnt others...
for example url work:
d=15&m=12&y=2014
but this:
d=12&m=12&y=2014
shows
fatal error: uncaught exception 'exception' message 'datetime::__construct(): failed parse time string (1418252400) @ position 7 (4): unexpected character' in
i have tried experimenting it, changing format of strtotime, no luck , seems randomly working....
when sending timestamp parameter of datetime object, have use @
symbol prefix. see manual (unix timestamp): http://php.net/manual/en/datetime.formats.compound.php
so, correct way is:
$datetime = new datetime('@' . $day, $datetimezone);
or, prefer:
$datetime = datetime($_get['y']."-".$_get['m']."-".$_get['d']);
Comments
Post a Comment