convert mysql timestamp to mktime

rashcroft picture rashcroft · Jun 30, 2009 · Viewed 10.9k times · Source

I have the following MySQL timestamp: 2009-06-23 16:21:48 How can I convert it to a format like mktime()?

Answer

Matt Bridges picture Matt Bridges · Jun 30, 2009

There is a MySQL function unix_timestamp. In your SQL query, instead of selecting the Datetime or Timestamp column directly, do this:

SELECT unix_timestamp(MyDatetimeColumn) FROM MyTable

Alternatively, if you have the string already, you could use the PHP function strtotime().