just having a little trouble converting between php time formats... not sure where I am off. Amongst other things, I am changing between 12 and 24 hour time.
$start_time= "02/12/2015 12:00 AM"; //this is a string
$myDateTime = DateTime::createFromFormat('m/d/Y h:i a', $start_time);
$newDateString = $myDateTime->format('Y-m-d H:i');
echo ($newDateString); //empty at the moment
My desired output format is:
2015-02-12 12:00
Sincere thanks for any help. It is greatly appreciated!
There is nothing wrong with your code except a missing ;
in the first line. Only one small change you can make. In the output you can change H
to h
since your desired output is in 12 hour format, rest is already fine.
$newDateString = $myDateTime->format('Y-m-d h:i');
2015-02-12 12:00
P.S: Sometimes i seriously wonder some up-votes were not necessary at all, I mean you could have run this code yourself and noticed it was already good. Just gave some up-votes to someone without taking any real help from them.
My Act of telling you that you are missing a ;
and need to change one letter is not a real help. Waste of time for you too :)