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

时间:2024-08-15 10:29:30

TIMESTAMPDIFF

  • 功能描述

    参考语法说明,本函数功能为返回timepoint1和timepoint2之间的时间间隔,间隔的单位由第一个参数timepointunit指定。

  • 语法说明
    INT TIMESTAMPDIFF(timepointunit, timepoint1, timepoint2)
  • 入参说明

    参数名

    数据类型

    参数说明

    timepointunit

    TIMEUNIT

    时间单位。取值范围为: SECOND、MINUTE、HOUR、DAY、MONTH、YEAR。

    timepoint1/timepoint2

    TIMESTAMP/DATE

    时间点。

  • 示例
    • 测试语句
      SELECT 
      	TIMESTAMPDIFF(DAY, TIMESTAMP '1997-04-25 10:00:00', TIMESTAMP '1997-04-28 10:00:00') AS `result`,
              TIMESTAMPDIFF(DAY, DATE '1997-04-25', DATE '1997-04-28') AS `result2`,
      	TIMESTAMPDIFF(DAY, TIMESTAMP '1997-04-27 10:00:20', TIMESTAMP '1997-04-25 10:00:00') AS `result3`
      FROM	testtable;
    • 测试结果

      result

      result2

      result3

      3

      3

      -2

support.huaweicloud.com/sqlreference-dli/dli_08_0429.html