INSERT into DB DateTime string

后端 未结 1 438
栀梦
栀梦 2020-12-31 12:22

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.

1条回答
  •  萌比男神i
    2020-12-31 12:55

    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).

    0 讨论(0)
提交回复
热议问题