I am trying to insert a date and time into the mysql datetime field from a string having the following format dd / mm / yyyy hh: mm: ss AM / PM :
20/10/2014 05:39 PM
20/10/2014 05:39 AM
I know the timestamp format of MYSQL is yyyy-mm-dd hh: mm: ss or 0000-00-00: 00: 00: 00
So if I do:
$s = substr("20/10/2014 05:39 PM", 0, 10);
$h = date("G:i", strtotime($s));
list($day, $month, $year, $hour, $minute) = split('[/ :]', "20/10/2014 05:39 PM");
echo $d1me = $year . '-' . $month. '-' . $day . ' ' . $h;
I get 2014-10-20 19:00
So, I think that there is a problem with the date_default_timezone_set () function, how to solve this problem and get the expected result?
20/10/2014 05:39 PM -> 2014-10-20 17:39:00
20/10/2014 05:39 AM -> 2014-10-20 05:39:00
How to do it?
source
share