I need to change a mysql timestamp from mysql format (ie: yyyy-mm-dd hh:mm:ss) to unix format.开发者_如何学运维
How would I write a query to change the datatype from timestamp to int, and convert all records to unix format in one fell swoop ?
Any help is appreciated :-)
If you add a new column of type INT UNSIGNED
to store the new UNIX time, you can run an UPDATE
command using UNIX_TIMESTAMP()
like the following:
UPDATE table
SET
newDateColumn = UNIX_TIMESTAMP(oldDateColumn)
Where oldDateColumn
is of type date
. Then afterwords you can drop the oldDateColumn
column (if you need/want to).
精彩评论