DateTime error while insert to MySQL

后端 未结 2 1149
萌比男神i
萌比男神i 2021-02-20 10:10

I come up with an error while inserting the following data into MySQL. How can I fix it?

ERROR 1292: Incorrect datetime value: \'17/07/2013 18:33:55\' for column \'TimeS

2条回答
  •  说谎
    说谎 (楼主)
    2021-02-20 10:45

    Alternatively, you can automatically re-format your date string to SQL-99 format using STR_TO_DATE():

    STR_TO_DATE( '17/07/2013 18:33:55', '%d/%m/%Y %H:%i:%s')
    

    So the INSERT statement would be:

    INSERT INTO wngtest.sitereading 
    (idSiteReading, TimeStamp, SiteLocation, Flow, Temperature1, Temperature2) 
    VALUES ('1', 
    STR_TO_DATE( '17/07/2013 18:33:55', '%d/%m/%Y %H:%i:%s'), 
    'WNGSite1', '13.1', '81', '45');
    

提交回复
热议问题