I am looking to convert a mysql timestamp to a epoch time in seconds using php, and vice versa. What's the cleanest way to do this?
+5
A:
There are two functions in MySQL which are useful for converting back and forth from the unix epoch time that PHP likes:
For example, to get it back in PHP unix time, you could do:
SELECT unix_timestamp(timestamp_col) FROM tbl WHERE ...
Harrison Fisk
2008-09-22 15:27:03
+6
A:
See strtotime and date functions in PHP manual.
$unixTimestamp = strtotime($mysqlDate);
$mysqlDate = date('Y-m-d h:i:s', $unixTimestamp);
Michał Rudnicki
2008-09-22 15:27:38
A:
From MySQL timestamp to epoch seconds:
strtotime($mysql_timestamp);
From epoch seconds to MySQL timestamp:
$mysql_timestamp = date('Y-m-d H:i:s', time());
Magsol
2008-09-22 15:27:57