SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2019-03-31 01:52:25'

无人久伴 提交于 2019-12-24 10:23:38

问题


I'm currently receiving lot's of errors from more than one production database that I maintain saying:

SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2019-03-31 01:49:45' for column 'created_at' at row 1 

This is my table:

+------------+--------------+------+-----+-------------------+----------------+
| Field      | Type         | Null | Key | Default           | Extra          |
+------------+--------------+------+-----+-------------------+----------------+
| id         | int(11)      | NO   | PRI | NULL              | auto_increment |
| log        | varchar(255) | YES  |     | NULL              |                |
| created_at | timestamp    | YES  |     | CURRENT_TIMESTAMP |                |
| updated_at | datetime     | YES  |     | NULL              |                |
+------------+--------------+------+-----+-------------------+----------------+

MySQL version:

mysql  Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using  EditLine wrapper

Can someone help me understand what's happening?


UPDATE:
I've no clue of what happened but I was receiving lot's of notifications from my error monitors and now all is back to normal without any change in the code from my side.

The errors started at: 2019-03-31 01:00:08
And ended at: 2019-03-31 01:59:03


UPDATE 2:
Ok so I'm from Portugal and today it was scheduled a national time change for +1 hour that I totally forgot...
I suspect the errors were due to my servers or my MySQL installation lagging in syncing with the new time.

I'll leave this question up in case anyone else encounters the same problem


回答1:


It's because of daylight savings time starting that day, so all times between 1am and 2am are invalid. You'll find the problem actually starts at '01:00:00' and ends at '01:59:59':

create table t (created_at timestamp null default current_timestamp);
insert into t values('2019-03-31 00:59:59');
insert into t values('2019-03-31 01:00:00');

Incorrect datetime value: '2019-03-31 01:00:00' for column 'created_at' at row 1

insert into t values('2019-03-31 01:59:59');

Incorrect datetime value: '2019-03-31 01:59:59' for column 'created_at' at row 1

insert into t values('2019-03-31 02:00:00');
select * from t

Output:

created_at
2019-03-31 00:59:59
2019-03-31 02:00:00

Changing your system timezone to one that does not have daylight savings time will solve the problem.



来源:https://stackoverflow.com/questions/55437250/sqlstate22007-invalid-datetime-format-1292-incorrect-datetime-value-2019-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!