Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error Code: 1411. I cannot convert a field from text data type to date

I cannot change the data type of the ‘Date’ field in my table (bus_delay) from text into date.

Date
1-Jan-22
2-Jan-22
3-Jan-22

When I run the following:

UPDATE bus_delay
SET Date = str_to_date(Date, "%d-%m-%y");

I receive the action response:
Error Code: 1411. Incorrect datetime value: ‘1-Jan-22’ for function str_to_date

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I believe I am using STR_TO_DATE() correctly, please correct me if I am wrong.

Note: When I execute:

DESCRIBE ttc_sql_project.bus_delay;

The field ‘Date’ returns a type of ‘text’.

>Solution :

The format string is wrong. This:

"%d-%m-%y"

Is looking for a date in this format:

"01-01-22"

But the format you have is:

"1-Jan-22"

Fix the format string:

"%e-%b-%y"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading