Mysql – Truncated Incorrect date value string with comma

MySQL

I have problem in date columns to insert from varchar column to date column.
I used str_to_date and Date_Format functions but it doesn't solved. How Can I

Simple Example:

update Uye_Uye_Liste 
set    DogumTarihi=str_to_date(DogumTarihi,'%d.%m.%Y') 
where  DogumTarihi is not null;

ERROR 1292 (22007): Truncated incorrect date value: '23.07.2002 00:00:00'

alter table Uye_Uye_Liste modify DogumTarihi datetime; 

ERROR 1292 (22007): Incorrect datetime value: '13-04-1996' for column 'DogumTarihi' at row 2

select DogumTarihi from Uye_Uye_Liste where DogumTarihi = '13.04.1996'; 

+-------------+ 
| DogumTarihi | 
+-------------+ 
| 13-04-1996  |
+-------------+ 

Best Answer

My guess is that you have one or more malformed values. Given the information you provided:

create table Uye_Uye_Liste ( DogumTarihi varchar(20) ) engine = innodb;
insert into Uye_Uye_Liste (DogumTarihi) values ('13.04.1996');

update Uye_Uye_Liste set DogumTarihi =  str_to_date(DogumTarihi,'%d.%m.%Y');
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0


alter table Uye_Uye_Liste modify DogumTarihi datetime;
Query OK, 1 row affected (0.06 sec)                
Records: 1  Duplicates: 0  Warnings: 0

So if every row corresponds to this pattern you should be alright. I suspect that some rows does not, focus on identifying and transforming those rows.

For the row given in the original query it is sufficient to to manually truncate the row using substr:

insert into Uye_Uye_Liste (DogumTarihi) values ('23.07.2002 00:00:00');
update Uye_Uye_Liste set DogumTarihi = str_to_date(substr(DogumTarihi,1,10),'%d.%m.%Y');
select * from Uye_Uye_Liste;
+-------------+
| DogumTarihi |
+-------------+
| 1996-04-13  |
| 2002-07-23  |
+-------------+
2 rows in set (0.00 sec)


alter table Uye_Uye_Liste modify DogumTarihi datetime;
Query OK, 2 rows affected (0.05 sec)               
Records: 2  Duplicates: 0  Warnings: 0