MySQL and Unix Timestamps

MySQL comes with two handy functions for working with unix timestamps. The unix timestamp or unix epoch time represents the number of seconds since midnight (UTC) 01/01/1970.

The two functions are:

  • unix_timestamp() to convert a standard date to unix timestamp format
  • from_unixtime() to convert a unix timestamp to standard date format

Note if you want the current date only (not time) in unix format use:

select unix_timestamp(curdate());

If you want the current date AND local time in unix format use:

select unix_timestamp(now());