数据湖探索 DLI-时间函数:TO_TIMESTAMP

时间:2023-11-01 16:20:09

TO_TIMESTAMP

  • 功能描述

    将string2格式的日期时间字符串string1转换为TIMESTAMP类型返回。

  • 语法说明
    TIMESTAMP TO_TIMESTAMP(string1[, string2])
  • 入参说明

    参数名

    数据类型

    参数说明

    string1

    STRING

    SQL时间戳形式的字符串。不符合格式的字符串会返回NULL。

    string2

    STRING

    日期字符串格式。如果该参数不指定,则默认为'yyyy-MM-dd HH:mm:ss' 。

  • 示例
    • 测试语句
      SELECT TO_TIMESTAMP('1997-04-25', 'yyyy-MM-dd') AS `result`,        TO_TIMESTAMP('1997-04-25 00:00:00') AS `result2`,        TO_TIMESTAMP('1997-04-25 00:00:00', 'yyyy-MM-dd HH:mm:ss') AS `result3`FROMtesttable;
    • 测试结果

      result

      result2

      result3

      1997-04-25 00:00

      1997-04-25 00:00

      1997-04-25 00:00

support.huaweicloud.com/sqlref-flink-dli/dli_08_0429.html