This topic describes how to use the date function TO_TIMESTAMP in Realtime Compute for Apache Flink.

Syntax

TIMESTAMP TO_TIMESTAMP(BIGINT time)
TIMESTAMP TO_TIMESTAMP(VARCHAR date)
TIMESTAMP TO_TIMESTAMP(VARCHAR date, VARCHAR format)

Input parameters

Parameter Data type
time BIGINT
Note The unit is milliseconds.
date VARCHAR
Note The default format is yyyy-MM-dd HH:mm:ss. If your date value is not in this format, use a Java UDF to convert the format. For more information, see UDF.
format VARCHAR

Description

Converts the type of a date from BIGINT or VARCHAR to TIMESTAMP.

Example

  • Test data
    timestamp1 (BIGINT) timestamp2 (VARCHAR) timestamp3 (VARCHAR)
    1513135677000 2017-09-15 00:00:00 20170915000000
  • Test statements
    SELECT TO_TIMESTAMP(timestamp1) as var1,
     TO_TIMESTAMP(timestamp2) as var2,
     TO_TIMESTAMP(timestamp3, 'yyyyMMddHHmmss') as var3
    FROM T1;
  • Test results
    var1 (TIMESTAMP) var2 (TIMESTAMP) var3 (TIMESTAMP)
    2017-12-13 03:27:57.0 2017-09-15 00:00:00.0 2017-09-15 00:00:00.0