This topic describes how to use the UNIX_TIMESTAMP function. This function converts a date value into a UNIX timestamp.

Limits

This function is supported only in Realtime Compute for Apache Flink that uses Ververica Runtime (VVR) 3.0.0 or later.

Syntax

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

Input parameters

ParameterData typeDescription
timestampTIMESTAMPN/A.
dateVARCHAR The default date format is yyyy-MM-dd HH:mm:ss.
formatVARCHAR The default date format is yyyy-MM-dd hh:mm:ss.

Example

  • Test data
    Table 1. T1
    date1(VARCHAR)date2(VARCHAR)
    2021-03-25 00:00:001970-01-01 00:00:00
  • Test statement
    SELECT UNIX_TIMESTAMP(TO_TIMESTAMP_TZ(date1,'Asia/Shanghai')) as big1,       
           UNIX_TIMESTAMP(date2) as big2
    FROM T1;
  • Test result
    big1(BIGINT)big2(BIGINT)
    1616601600-28800