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