Convert datepicker to mysql datetime format in PHP
Is there a way to convert a date in this format: 08/19/2014 1:45 pm
in MySQL datetime format such as 2014-08-19 13:45:00.
I tried using something like
date("Y-m-d H:i:s", $myTime);
but I don't think it likes "pm" and it returns 1969-12-31 giving an error:
"Incorrectly formed numeric value"
+3
user2994560
source
to share
2 answers
Have you tried using strtotime()
?
$myTime = strtotime("08/19/2014 1:45 pm");
echo date("Y-m-d H:i:s", $myTime);
Output :
2014-08-19 13:45:00
+10
Lenny
source
to share
This works for dd / mm / yyyy
$date = '18/03/2016 16:25';
echo date("Y-m-d H:i:s",strtotime(str_replace('/','-',$date)));
=> 2016-03-18 16:25:00
+1
Fury
source
to share