Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Truncated incorrect datetime value mysql

Tags:

datetime

mysql

I am trying to convert my strings to datetimes, and it works for some but not all. I assume it's because mysql doesn't understand miliseconds. But is there a way to tell it to ignore the miliseconds, or how could I remove the part after the last period, make a new column, and convert that column to datetime. The result and input is shown below.

I am using set @@sql_mode='no_engine_substitution';, which I found on another stackoverflow question, but it doesn't seem to help.

1292 Truncated incorrect datetime value: '2015-03-16 08.36.20.814000' 
Rows matched: 156192044  Changed: 105813258  Warnings: 156088004

I'm using the method suggested on my previous question to convert them. Convert String to Datetime Object in SQL

My update query is:

update marketwatch_data set `datetime` = STR_TO_DATE(`Update Time`,'%Y-%m-%d %h.%i.%s');
like image 982
nicholas.reichel Avatar asked Aug 25 '26 16:08

nicholas.reichel


1 Answers

You can use substring_index():

update marketwatch_data
    set `datetime` = STR_TO_DATE(substring_index(`Update Time`, '.', 3),
                                 '%Y-%m-%d %h.%i.%s');
like image 184
Gordon Linoff Avatar answered Aug 29 '26 22:08

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!