Convert string from dd/mm/yyyy to yyyy-mm-dd using mysql

I had a large dataset with all the date fields in the format DD/MM/YYYY. I needed to convert them to YYYY-MM-DD . I ran the following queries:

UPDATE TABLE_NAME SET FIELD_NAME = replace(FIELD_NAME, '/', '-');

UPDATE TABLE_NAME SET FIELD_NAME = str_to_date(FIELD_NAME,'%d-%m-%Y');

Hope it helps…

1 Comment

  1. Douglas Sesar

    Hey thank you very much for this post; It was exactly what I needed.

    Reply

Leave a Reply to Douglas Sesar Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>