Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Converting string date and time to MySQL DateTime [duplicate]

I have two text fields, one for the date in 08/01/2012 format and a second field containing the time. I currently have the time field in the format 09:41am but I have some flexibility with it's format (if 24hr is easier for example).

I was planning on just concatenating the strings and then converting. Should I convert the date to 2012-08-01 first?

How can I end up converting to datetime (2012-08-01 09:41:00)? How to convert back out of it into a 08/01/2012 and 09:41am format?

like image 853
Motive Avatar asked Aug 01 '12 16:08

Motive


1 Answers

SELECT STR_TO_DATE(concat('08/01/2012', '09:41am'),'%d/%m/%Y%h:%i');
like image 70
juergen d Avatar answered Sep 21 '22 07:09

juergen d