Convert varchar column to date in mysql at database level

后端 未结 3 1873
难免孤独
难免孤独 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:55

    use STR_TO_DATE Function of MySQL

    FIRST you will need to update the value in date format.

    UPDATE `tbl` SET `date1` = STR_TO_DATE(`date1`, '%d-%m-%Y') WHERE 1=1
    

    THEN Convert the field to date.

    Most importantly remember to insert date as Y-m-d format, after then.

提交回复
热议问题