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

孤街醉人 提交于 2019-11-29 06:24:01

问题


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


回答1:


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




回答2:


Try this query.

ALTER TABLE  `table_name` CHANGE  `From Date`  `From Date` DATETIME NULL DEFAULT '0000-00-00 00:00:00';



回答3:


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



来源:https://stackoverflow.com/questions/15335880/how-to-change-varchar-type-to-datetime-using-alter-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!