Is there a way I can convert a date in this format: 08/19/2014 1:45 pm
into MySQL datetime format like 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 the 'pm' and gives back 1969-12-31, giving error:
"A non well formed numeric value encountered"
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
This works on 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With