MySQL Mysql日期警告数据被截断

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21305092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:53:55  来源:igfitidea点击:

Mysql date warning data truncated

mysqldateformatwarnings

提问by Gui O

I'm having an interesting issue with Mysql DATE format. I have this table :

我在 Mysql DATE 格式方面遇到了一个有趣的问题。我有这张桌子:

| id          | int(11)      | NO   | PRI | NULL    | auto_increment |
| file_path   | varchar(255) | YES  |     | NULL    |                |
| date_export | date         | YES  |     | NULL    |                |

When i'm updating a row using the date function : NOW(), the date is updated with this format :

当我使用日期函数更新一行时:NOW(),日期更新为以下格式:

'2014-01-23'

But when i'm using another date format, like hand-written one like :

但是当我使用另一种日期格式时,比如手写的:

update backup_conf_allied set date_export='2014-23-01' where file_path='IDF-952584-SW1' ;

The date_export column transforms into :

date_export 列转换为:

'0000-00-00'

Warning table tells me that :

警告表告诉我:

| Warning | 1265 | Data truncated for column 'date_export' at row 3628 |

Why? The date format is the same as NOW() function. Thanks.

为什么?日期格式与 NOW() 函数相同。谢谢。

回答by Abdul Manaf

Posted query

发布查询

update backup_conf_allied set `date_export='2014-23-01'` where file_path='IDF-952584-SW1' ;

What it should be

它应该是什么

update backup_conf_allied set `date_export='2014-01-23'` where file_path='IDF-952584-SW1' ;

MySQL Support DATE format as 'YYYY-MM-DD' , Year then Month then Date, So you are updating a Date column with wrong value "2014-23-01", There are only 12 months in year, you are using month 23 which is invalid that's MySQL is converting it to ZERO DATE (0000-00-00)

MySQL 支持 DATE 格式为 'YYYY-MM-DD' ,Year then Month then Date因此您正在更新具有错误值的日期列,"2014-23-01"一年中只有 12 个月,您使用的是无效的第 23 个月,因为 MySQL 正在将其转换为 ZERO DATE( 0000-00-00)

回答by Everyone_Else

I had a similar problem recently, my issue was that I was trying to upload a datetime object as a date object. Although that's not the same issue that Gui O was having, if you run into this, make sure that you're actually trying to upload a date object.

我最近遇到了类似的问题,我的问题是我试图将日期时间对象作为日期对象上传。尽管这与 Gui O 遇到的问题不同,但如果您遇到此问题,请确保您实际上是在尝试上传日期对象。