12

I have the string 04/04/2012 04:03:35 AM. How can I convert it and insert into a table? Field type is datetime.

ballade4op52
  • 2,142
  • 5
  • 27
  • 42
Anton Sementsov
  • 1,196
  • 6
  • 18
  • 34

1 Answers1

21

You need to use STR_TO_DATE():

STR_TO_DATE('04/04/2012 04:03:35 AM', '%d/%m/%Y %r')

Or, better yet, present your literal in a format MySQL expects (e.g. YYYY-MM-DD HH:mm).

eggyal
  • 122,705
  • 18
  • 212
  • 237