Error code 1292 Mysql DateTime

后端 未结 2 2000
隐瞒了意图╮
隐瞒了意图╮ 2020-12-22 02:29

I am trying to format a date and a time that comes in one column called DATE as DD/MM/YYYY (Varchar) and in another column called TIME as HH:MM:SS into one variable to inser

相关标签:
2条回答
  • 2020-12-22 02:41

    Somehow your LMONTH and LDAY values seem to be reversed as LMONTH is getting written as 31 and LDAY as 01 - which obviously incorrect. Check the data within your source table.

    0 讨论(0)
  • 2020-12-22 02:47

    Look at the value:

    '2013-31-01 16:00:40'
    

    That's trying to use a month of 31.

    It's not clear whether that just means your test data is wrong, or whether you need to change these lines:

    SELECT SUBSTRING(DATE,3,2) FROM db.test_table INTO LMONTH;
    SELECT SUBSTRING(DATE,1,1) FROM db.test_table INTO LDAY;
    

    to:

    SELECT SUBSTRING(DATE,1,2) FROM db.test_table INTO LMONTH;
    SELECT SUBSTRING(DATE,4,2) FROM db.test_table INTO LDAY;
    

    Note the change from 1 to 2 for the substring starting at 1 anyway, and the change of the second starting position from 3 to 4. You want two-digit month and day values, right? If your data format is actually D/M/YYYY (i.e. only using two digits when they're required) then you won't be able to use fixed substring positions.

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