Skip to content

FROM_UNIXTIME()

Function Description

The FROM_UNIXTIME() function converts the internal UNIX timestamp value to a date and time value in normal format and displays it in YYYY-MM-DD HH:MM:SS or YYYMMDDHHMMSS format. It is inverse to the UNIX_TIMESTAMP () function.

Function Syntax

> FROM_UNIXTIME(unix_timestamp[,format])

Parameter definition

Parameters Description
format Optional parameters. A format string representing the format of the return value.
If format is omitted, a DATETIME value is returned.
If format is empty, return NULL.
format is used to format the results in the same way as the format string used by the DATE_FORMAT() function. If format already has the specified format, the return value is VARCHAR.
unix_timestamp Required parameters. Time stamp, a field in the database that stores time data.
If unix_timestamp is empty, NULL is returned.
If unix_timestamp is an integer, the fractional-second accuracy of DATETIME is zero. When unix_timestamp is a decimal value, the decimal second accuracy of DATETIME is the same as the decimal value, up to 6 seconds. When unix_timestamp is a floating point number, the minute-second accuracy of datetime is 6.

Example

mysql> SELECT FROM_UNIXTIME(1447430881);
+--------------------------------+
| from_unixtime(1447430881) |
+--------------------------------+
| 2015-11-14 00:08:01 |
+--------------------------------+
1 row in set (0.00 sec)

mysql> SELECT FROM_UNIXTIME(1447430881, '%Y %D %M %h:%i:%s %x');
+------------------------------------------------------------------+
| from_unixtime(1447430881, %Y %D %M %h:%i:%s %x) |
+------------------------------------------------------------------+
| 2015 14th November 12:08:01 2015 |
+------------------------------------------------------------------+
1 row in set (0.00 sec)

limit

Currently, the date format only supports the data formats of yyyy-mm-dd and yyyymmdd.