Skip to content

Instantly share code, notes, and snippets.

@daGrevis
Created January 17, 2012 06:04
Show Gist options
  • Save daGrevis/1625091 to your computer and use it in GitHub Desktop.
Save daGrevis/1625091 to your computer and use it in GitHub Desktop.
Timestamp to datetime
@nexeck
Copy link

nexeck commented Jan 17, 2012

If you want to change this within MySQL You could try this:

ALTER TABLE `table1` CHANGE `time` `unix_time` int(11) NOT NULL /* rename the old column */
ALTER TABLE `table1` ADD `time` DATETIME NOT NULL /* create the datetime column */
UPDATE `table1` SET `time`=FROM_UNIXTIME(unix_time) /* convert the data */
ALTER TABLE `table1` DROP `unix_time` /* drop the old unix time column */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment