MySQL convert datetime to unixtime?

I have a column with the DATETIME format, and I would like to convert it to UNIXTIME in the database. What will be the request?

I know how to convert from UNIXTIME to DATETIME, but I have never done the opposite. I used FROM_UNIXTIME, is there TO_UNIXTIME?

+4
source share
2 answers

This is UNIX_TIMESTAMP . As an argument, this will take a formatted datetime.

+8
source

Everything is fine, I get it.

I had an "article_date" for the source column. I created "new_date" for the new column.

Then I did:

 UPDATE news SET new_date = UNIX_TIMESTAMP(article_date) 
+4
source

Source: https://habr.com/ru/post/1499452/


All Articles