Edit

from_unixtime

description

Syntax

DATETIME FROM_UNIXTIME(INT unix_timestamp[, VARCHAR string_format])

onvert the unix timestamp to the corresponding time format. The format returned should be specified by string_format.

The default format is yyyy-MM-dd HH:mm:ss. It also supports the formats in date_format.

It inputs integers and returns strings.

Currently, string_format supports the following formats:

%Y:Year  e.g.:2014,1900
%m:Month   e.g.:12,09
%d:Day  e.g.:11,01
%H:Hour  e.g.:23,01,12
%i:Minute  e.g.:05,11
%s:Second  e.g.:59,01

Other formats in string_format are invalid and be returned as NULL.

If the specified timstamp is less than 0 or more than 253402271999, it will be returned as NULL. The range for timestamp is: 1970-01-01 00:00:00 ~ 9999-12-31 23:59:59.

example

MySQL > select from_unixtime(1196440219);
+---------------------------+
| from_unixtime(1196440219) |
+---------------------------+
| 2007-12-01 00:30:19       |
+---------------------------+

MySQL > select from_unixtime(1196440219, 'yyyy-MM-dd HH:mm:ss');
+--------------------------------------------------+
| from_unixtime(1196440219, 'yyyy-MM-dd HH:mm:ss') |
+--------------------------------------------------+
| 2007-12-01 00:30:19                              |
+--------------------------------------------------+

MySQL > select from_unixtime(1196440219, '%Y-%m-%d');
+-----------------------------------------+
| from_unixtime(1196440219, '%Y-%m-%d')   |
+-----------------------------------------+
| 2007-12-01                              |
+-----------------------------------------+

MySQL > select from_unixtime(1196440219, '%Y-%m-%d %H:%i:%s');
+--------------------------------------------------+
| from_unixtime(1196440219, '%Y-%m-%d %H:%i:%s')   |
+--------------------------------------------------+
| 2007-12-01 00:30:19                              |
+--------------------------------------------------+

keyword

FROM_UNIXTIME,FROM,UNIXTIME