Convert varchar column to date in mysql at database level

后端 未结 3 1899
难免孤独
难免孤独 2020-12-11 01:05

I have one column date1 which is varchar type I want this column to date type. I tried changing field but all date is converted to 0

3条回答
  •  难免孤独
    2020-12-11 01:29

    UPDATE `table`
    SET `column` = str_to_date( `column`, '%d-%m-%Y' );
    

    More about STR_TO_DATE function.


    Since your column name is date1, you can replace column with date1 in the above syntax, and the code shall be:

    UPDATE `table`
    SET `date1` = str_to_date( `date1`, '%d-%m-%Y' );
    

提交回复
热议问题