将mySQL Column数据类型从text更改为timestamp

时间:2022-12-10 16:57:11

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 format)

如何将列的数据类型从文本更改为时间戳。当前文本列以以下格式存储日期:'2010-08-15'(yyyy-mm-dd sql格式)

2 个解决方案

#1


19  

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.

链接到文档。

#2


2  

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.

其中table_name是表的名称,field_name是您希望更改其类型的字段的名称。

#1


19  

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.

链接到文档。

#2


2  

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.

其中table_name是表的名称,field_name是您希望更改其类型的字段的名称。