MySQL 1292 Incorrect datetime value

六眼飞鱼酱① 提交于 2019-11-29 10:09:45

It took me a while to figure this out...

The problem is that '2011-03-13 02:53:50' is illegal because of daylight saving time switch between 2 and 3 AM, so all time values between 2 and 3 am on any DST introduction day are invalid. Same for '2016-03-13 02:32:21', etc.

Change the system timezone to the one that does not use DST and you should be fine.

You need to try this:

STR_TO_DATE( '2011/03/13 02:53:50', '%Y/%m/%d %H:%i:%s')

or else you have to insert the dates using the dash seperator (-) like

'2011-03-13 02:53:50' 

SQL FIDDLE DEMO

I think you need to use some str conversions in MySQL before inserting. Or to prepare the data in the proper format, before making the query to MySQL.

The microseconds format is also wrong. MySQL documentation clearly states this:

A DATETIME or TIMESTAMP value can include a trailing fractional seconds part in up to microseconds (6 digits) precision.


UPDATE: on my localhost I've got the same version of MySQL, and it works. Tryed to execute conversion

select str_to_date("2011-03-13 02:53:50.000000", "%Y-%m-%d %H:%i:%s.%f") as `t`

and gotten:

+----------------------------+
| t                          |
+----------------------------+
| 2011-03-13 02:53:50.000000 |
+----------------------------+
1 row in set (0.00 sec)

Here's the SQLFiddle, that confirms the thing on other version of MySQL.

I run out of ideas, I think the issue is connected to the "local glitch" in Table structure or specific version of MySQL+OS.

Still not sure what the issue is/was, maybe a combination of CentOS and MySQL versions. I changed the column to datatime(6) instead of timestamp(6) and I was able to import all my data successfully.

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