Copy

Current unix time / stamp :

1498417306

Unix time in MySQL

MySQL features several flexible functions just for Unix time, but let's start with getting the Unix timestamp itself.

UNIX_TIMESTAMP(now())

That's all there is to it! You can use it directly in your MySQL statements and it will represent the current unix timestamp.

An example use showing an INSERT into an imaginary table of 3 fields, where the last field is for timestamps:

INSERT INTO tableName VALUES('someField', 'someOtherField', UNIX_TIMESTAMP(now()))

When you want to return a Unix time in the database as a human readable date, FROM_UNIXTIME() does the trick:

FROM_UNIXTIME(fieldName, '%Y-%m-%d')

You don't have to include the second parameter, which tells MYSQL how we want to have the date formatted, but I included it with an example as you don't probably want to be stuck with the default date format. Head on over to the official FROM_UNIXTIME function documentation for information on how to further customize this function.