php - strtotime and DateTime giving wrong year when parsing a year -
$year = date('y', strtotime("2012")); var_dump($year);//returns 2013 this happening old server php 5.2 , new 1 php 5.4
the server uses strtotime year string 2012-01-01 or 2012-01 or 2012
i tried using $dt = new datetime('2012') , gettimestamp returns "1374516720" "mon, 22 jul 2013 18:12:00 gmt"
what causing bug? in documentation says strtotime accepts year
i don't know do...
edit:
$year = date('y', strtotime("2012")); gets treated military time, 20:12 current year
using complete date string yyyy-mm-dd , 01.01 day did trick me:
$year = date('y', strtotime("2012-01-01")); var_dump($year);//returns 2012 normally suggest use datetime::createfromformat() @rufinus suggested, method not available in php5.2 (what using on 1 of servers). maybe reason fro upgrading old one? ;)
reasons why happens:
while manual says @ 1 point yyyy (and yyyy) formats ok, tells restrictions behaviour lines below: strtotime() called yyyy under special circumstances return time stamp today, 20:12:
the "year (and year)" format works if time string has been found -- otherwise format recognised hh mm.
i don't know mean when saying a time string has been found. can see behaviour using following line:
var_dump(date("y-m-d h:i:s", strtotime('2012'))); // output: string(19) "2013-07-22 20:12:00" this leads result 2013.
Comments
Post a Comment