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

Syntax

BIGINT UNIX_TIMESTAMP()
BIGINT UNIX_TIMESTAMP(VARCHAR date)
BIGINT UNIX_TIMESTAMP(TIMESTAMP timestamp)
BIGINT UNIX_TIMESTAMP(VARCHAR date, VARCHAR format)

Input parameters

Parameter Data type
timestamp TIMESTAMP
date VARCHAR
Note The default date format is yyyy-MM-dd HH:mm:ss.
format VARCHAR
Note The default format is yyyy-MM-dd hh:mm:ss.

Description

Converts the specified date to a UNIX timestamp (in seconds) of the LONG type. If no input parameter is specified, the UNIX timestamp (in seconds) of the current time is returned. In this case, this function has the same semantics as NOW. If an input parameter is null or a parsing error occurs, null is returned.

Example

  • Test data
    nullstr (VARCHAR)
    null
  • Test statements
    SELECT UNIX_TIMESTAMP() as big1,
           UNIX_TIMESTAMP(nullstr) as big2
    FROM T1;
  • Test results
    big1 (BIGINT) big2 (BIGINT)
    1403006911 null