This topic describes how to use the date function FROM_UNIXTIME in Realtime Compute.

Syntax

VARCHAR FROM_UNIXTIME(BIGINT unixtime[, VARCHAR format])

Input parameters

Parameter Data type
unixtime BIGINT
format VARCHAR
Note
  • The unixtime parameter is a long integer, which is a timestamp in seconds.
  • The format parameter is optional and is in the date format. The default format is yyyy-MM-dd HH:mm:ss. This parameter indicates that a date value of the VARCHAR type in the specified date format is returned. If any input parameter is null or a parsing error occurs, null is returned.

Description

Returns a date value of the VARCHAR type in the specified date format. The default format is yyyy-MM-dd HH:mm:ss. If any input parameter is null, null is returned.

Example

  • Test data
    unixtime1 (BIGINT) nullstr (VARCHAR)
    1505404800 null
  • Test statements
    SELECT FROM_UNIXTIME(unixtime1) as var1, 
     FROM_UNIXTIME(unixtime1,'MMdd-yyyy') as var2,
     FROM_UNIXTIME(unixtime1,nullstr) as var3
    FROM T1;               
  • Test results
    var1 (VARCHAR) var2 (VARCHAR) var3 (VARCHAR)
    2017-09-15 00:00:00 0915-2017 null