from_unixtime

description

syntax

DATETIME FROM UNIXTIME (INT unix timestamp [, VARCHAR string format]

Convert the UNIX timestamp to the corresponding time format of bits, and the format returned is specified by string_format

Input is an integer and return is a string type

Currently, string_format supports following formats:

  1. %Y: Year. eg. 20141900
  2. %m: Month. eg. 1209
  3. %d: Day. eg. 1101
  4. %H: Hour. eg. 230112
  5. %i: Minute. eg. 0511
  6. %s: Second. eg. 5901

Default is %Y-%m-%d %H:%i:%s

Other string_format is illegal and will returns NULL.

example

  1. mysql> select from_unixtime(1196440219);
  2. +---------------------------+
  3. | from_unixtime(1196440219) |
  4. +---------------------------+
  5. | 2007-12-01 00:30:19 |
  6. +---------------------------+
  7. mysql> select from_unixtime(1196440219, '%Y-%m-%d');
  8. +-----------------------------------------+
  9. | from_unixtime(1196440219, '%Y-%m-%d') |
  10. +-----------------------------------------+
  11. | 2007-12-01 |
  12. +-----------------------------------------+
  13. mysql> select from_unixtime(1196440219, '%Y-%m-%d %H:%i:%s');
  14. +--------------------------------------------------+
  15. |From unixtime (1196440219,'%Y-%m-%d %H:%i:%s') |
  16. +--------------------------------------------------+
  17. | 2007-12-01 00:30:19 |
  18. +--------------------------------------------------+
  19. ##keyword
  20. FROM_UNIXTIME,FROM,UNIXTIME