简体   繁体   中英

Convert datepicker time to mysql datetime format in PHP

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM