9

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?

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156

2 Answers2

13

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

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
5

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)