开发者

change timestamps from mysql format to unix - MYSQL

开发者 https://www.devze.com 2023-03-20 22:55 出处:网络
I need to change a mysql timestamp from mysql format (ie: yyyy-mm-dd hh:mm:ss) to unix format.开发者_如何学运维

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号