如何在 MySQL 中使用 ALTER 将 VARCHAR 类型更改为 DATETIME?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15335880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change VARCHAR type to DATETIME using ALTER in MySQL?
提问by aizaz
How can I change VARCHAR()
type to DATETIME
using ALTER
in MySQL?
如何将VARCHAR()
类型更改为在 MySQL 中DATETIME
使用ALTER
?
回答by Meherzad
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
回答by Dhinakar
Try this query.
试试这个查询。
ALTER TABLE `table_name` CHANGE `From Date` `From Date` DATETIME NULL DEFAULT '0000-00-00 00:00:00';
回答by Dhinakar
Why not you just use
你为什么不直接使用
STR_TO_DATE(str,format)
,
STR_TO_DATE(str,format)
,
It takes a string str and a format string format and returns a DATETIMEvalue if the format string contains both date and time parts.
它接受一个字符串 str 和一个格式字符串格式,如果格式字符串同时包含日期和时间部分,则返回一个DATETIME值。
Reffer this LINK, Hope it may help you
参考这个链接,希望它可以帮助你