Convert date to datetime or timestamp using alter table in mysql

I have a table in mysql with DATE column, now I need to convert these values to DATETIME or TIMESTAMP.

I wonder what will happen with data when I'll do:

ALTER TABLE sample MODIFY sample_date DATETIME

or

ALTER TABLE sample MODIFY sample_date TIMESTAMP

It's pretty straight forward to convert from one type to another using the ALTER TABLE command:

ALTER TABLE table_name CHANGE old_date new_timestamp TIMESTAMP This process may take a while to complete if you have a lot of data and a large number of indexes.

I'm not sure why you'd want to switch these to the TIMESTAMP type as that has a much more limited range than DATETIME. The differences are documented and important to know.

链接地址: http://www.djcxy.com/p/25068.html

上一篇: 从MySQL Epoch开始,JDBC MySQL读取和写入TIMESTAMP为毫秒

下一篇: 使用mysql中的alter table将日期转换为日期时间或时间戳