MySQL convert datetime to unixtime?

荒凉一梦 提交于 2020-01-13 08:45:09

问题


I have a column with the DATETIME format and I would like to convert it to UNIXTIME in the database. What kind of query would that be?

I know how to convert from UNIXTIME to DATETIME, but I've never done the reverse. I've used FROM_UNIXTIME, is there no TO_UNIXTIME?


回答1:


It's UNIX_TIMESTAMP. This will take a properly formatted datetime as an argument.




回答2:


It's okay, I figured it out.

I had 'article_date' for the original column. I created 'new_date' for the new column.

Then I did:

UPDATE news SET new_date = UNIX_TIMESTAMP(article_date)


来源:https://stackoverflow.com/questions/18494493/mysql-convert-datetime-to-unixtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!