开发者

Change a mySQL Column datatype from text to timestamp

开发者 https://www.devze.com 2023-02-02 12:43 出处:网络
How can I change the datatype of a column from text to timestamp. The current text column is storing dates in the format : \'2010-08-15\' (yyyy-mm-dd sql fo开发者_高级运维rmat)ALTER TABLE `mydb`.`myta

How can I change the datatype of a column from text to timestamp. The current text column is storing dates in the format : '2010-08-15' (yyyy-mm-dd sql fo开发者_高级运维rmat)


ALTER TABLE `mydb`.`mytable` MODIFY COLUMN `mycol` TIMESTAMP;

Using the above command a value such as:

'2010-08-15'

will change to

TIMESTAMP '2010-08-15 00:00:00'

Link to documentation.


Have you tried this

alter table table_name change field_name field_name timestamp;

where table_name is the name of the table and field_name is the name of the field that you wanted alter the type of.

0

精彩评论

暂无评论...
验证码 换一张
取 消