How to change VARCHAR type to DATETIME using ALTER in MySQL?

后端 未结 3 1265
北海茫月
北海茫月 2020-12-30 00:34

How can I change VARCHAR() type to DATETIME using ALTER in MySQL?

相关标签:
3条回答
  • 2020-12-30 01:11

    Try this query.

    ALTER TABLE  `table_name` CHANGE  `From Date`  `From Date` DATETIME NULL DEFAULT '0000-00-00 00:00:00';
    
    0 讨论(0)
  • 2020-12-30 01:33
    ALTER TABLE <tblName> MODIFY <columnName> dataType constraint;
    

    For your requirement it will be

    ALTER TABLE <tblName> MODIFY <columnName> datetime;
    

    Refer http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

    0 讨论(0)
  • 2020-12-30 01:34

    Why not you just use

    STR_TO_DATE(str,format) ,

    It takes a string str and a format string format and returns a DATETIME value if the format string contains both date and time parts.

    Reffer this LINK , Hope it may help you

    0 讨论(0)
提交回复
热议问题