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?
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?
From MySQL timestamp to epoch seconds:
From epoch seconds to MySQL timestamp:
See strtotime and date functions in PHP manual.
There are two functions in MySQL which are useful for converting back and forth from the unix epoch time that PHP likes:
from_unixtime()
unix_timestamp()
For example, to get it back in PHP unix time, you could do: