echo date('Y-m-d',strtotime('02-12-13'));
It's english format so
Expected output: 2013-12-02
My output: 2002-12-13
Any one knows what's going on?
The paramter to strtotime is parsed as yy "-" MM "-" DD
format when you specify the year with only two digits. See http://www.php.net/manual/en/datetime.formats.date.php (in the ISO8601 notations).
If you specify the year with four digits, i.e., 02-12-2013
, you should get your expected result.
"xx-xx-xx" is interpreted as "yy-mm-dd", as specified in the manual: http://www.php.net/manual/en/datetime.formats.date.php
You have to use date_parse_from_format () and use the returned array to build the correct format.
http://de3.php.net/manual/en/function.date-parse-from-format.php
however, maybe it is better to just format your original us date string with simple string manipulation.
Convert UK date to US date in PHP with different separator
list($date,$month,$year) = sscanf("01/01/2012", "%d/%d/%d");
echo "$month-$date-$year";