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
Insert Date and Timestamp Using NOW FunctionRight-click on the cell and select 'Format cells'. In the Format Cells dialog box, select 'Custom' category in the Number tab. In the Type field, enter dd-mm-yyyy hh:mm:ss. Click OK.
Here is the SQL you can use to add the column in: ALTER TABLE `table1` ADD `lastUpdated` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ; This adds a column called 'lastUpdated' with a default value of the current date/time.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With