Friday 5 August 2022

MySQL Data truncation: Incorrect datetime value

 This got me going today.  Trying to alter a datetime column to timestamp.  Fails on a single row with date '2011-10-02 02:29:42'

Gives the following error message:

SQL State  : 22001
Error Code : 1292
Message    : Data truncation: Incorrect datetime value: '2011-10-02 02:29:42' for column 'date' at row 6151

I check the format of the date again and again.  And again.  It's definitely ok.  Change the year and it works, but change the seconds on it doesn't.  WTF is going on?

Well, it's daylight saving.  Check internet and sure enough in Australia daylight saving change on  2011-10-02 moved the clocks forward one hour from 2am to 3am.  So any timestamp value between 2am and 3am is invalid (in this timezone)!