Convert Varchar column to Date without losing the data

Asked

Viewed 133 times

0

Before the database was saving the date in a varchar field and in the Brazilian standard (dd/mm/YYYY), then I modified the values using the code below:

UPDATE tabela SET coluna= DATE_FORMAT(STR_TO_DATE(coluna, '%d/%m/%Y'), '%Y-%m-%d')
WHERE coluna LIKE '__/__/____';

At that point it worked perfectly, stayed in the pattern YYYY-mm-dd, but when changing from varchar to date it ended up erasing all my data and filling with 0000-00-00.

  • https://stackoverflow.com/questions/7090231/how-to-convert-a-varchar-column-type-to-date-type-without-losing-the-dates

  • I had seen this link @Leocaracciolo but for me it is impossible to replicate all by the large amount of tables and columns I have, even so thank you!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.