How can I convert a js Date (like this Sun Jul 13 2014 07:00:00 GMT+0200 (EET)
) to MySQL format (like this 2014-07-13 07:00:00
) using php ?
I will try to enhance @akuzminsky answer a little. Since date_parse
is using strtotime
internally to parse the date, you can use it directly and make your code more flexible.
There is a small drawback since you need to set the time zone in order to use date
correctly and avoid php warning. I am setting it to Europe/Athens
but you can find here all available codes.
date_default_timezone_set("Europe/Athens");
$unixTimeStamp = strtotime("Sun Jul 13 2014 07:00:00 GMT+0200 (EET)");
$newFormat = date('Y-m-d H:i:s', $unixTimeStamp );
echo $newFormat;