I using PHP’s strtotime function for converting date from one format to another
i have the following
$date = "12-22-2011";
echo $newDateFormat = date("Y-m-d", strtotime($date) );
// Output 1970-01-01
// But when i replace "-" with "/" I get proper output
$date = "12/22/2011";
echo $newDateFormat = date("Y-m-d", strtotime($date) );
// Output 2011-12-22
Why so ?
or is there any other function which accepts anything and convert to proper date format ?
From the strtotime documentation:
Essentially, hyphenated dates are assumed to be d-m-y, and never m-d-y.
For customised parsing, use
DateTime::createFromFormat().