FROM_UNIXTIME Function

Description

The FROM_UNIXTIME function returns the date and time in the format of 'YYYY-MM-DD HH:MM:SS.' You can specify INTEGER type that corresponds to the UNIX timestamp; the value is returned in VARCHAR type and is displayed in the current time zone.

It displays the result according to the format that you specified, and the time format format follows the Date/Time Format 2 table of DATE_FORMAT Function.

The relationship is not one of one-to-one correspondence between TIMESTAMP and UNIX timestamp so if you use UNIX_TIMESTAMP or FROM_UNIXTIME function, partial value could be lost. For details, see UNIX_TIMESTAMP Function.

0 is not allowed in the argument value corresponding to year, month, and day; however, if 0 is inputted in every argument value corresponding to date and time, string where 0 is specified for every date and time value is returned. Note that operation in JDBC program is determined by the configuration of zeroDateTimeBehavior, connection URL property (see "API Reference > JDBC API > JDBC Programming > Connection Configuration").

Syntax

FROM_UNIXTIME( unix_timestamp[, format] )

Example

SELECT FROM_UNIXTIME(1234567890);

   from_unixtime(1234567890)

============================

  01:31:30 AM 02/14/2009

 

SELECT FROM_UNIXTIME('1000000000');

   from_unixtime('1000000000')

==============================

  04:46:40 AM 09/09/2001

 

SELECT FROM_UNIXTIME(1234567890,'%M %Y %W');

   from_unixtime(1234567890, '%M %Y %W')

======================

  'February 2009 Saturday'

 

SELECT FROM_UNIXTIME('1234567890','%M %Y %W');

   from_unixtime('1234567890', '%M %Y %W')

======================

  'February 2009 Saturday'

 

SELECT FROM_UNIXTIME(-1);

ERROR: Conversion error in timestamp format.

Download in other formats:

 

SELECT FROM_UNIXTIME(-1);

ERROR: Conversion error in timestamp format.

Download in other formats:

 

SELECT FROM_UNIXTIME(0);

   from_unixtime(0)

===========================

   12:00:00 AM 00/00/0000