Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql date warning data truncated

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

| 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 :

'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 :

'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.

like image 989
Gui O Avatar asked Jan 23 '14 10:01

Gui O


People also ask

What is data truncated in MySQL?

TRUNCATE TABLE empties a table completely. It requires the DROP privilege. Logically, TRUNCATE TABLE is similar to a DELETE statement that deletes all rows, or a sequence of DROP TABLE and CREATE TABLE statements. To achieve high performance, TRUNCATE TABLE bypasses the DML method of deleting data.

Why is my data truncated?

In databases and computer networking data truncation occurs when data or a data stream (such as a file) is stored in a location too short to hold its entire length.

Does MySQL support date data type?

MySQL retrieves and displays DATE values in ' YYYY-MM-DD ' format. The supported range is '1000-01-01' to '9999-12-31' . The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format.


1 Answers

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)

like image 107
Abdul Manaf Avatar answered Nov 21 '22 05:11

Abdul Manaf