全部产品
阿里云办公

HOUR

更新时间:2018-10-10 10:02:21

语法

  1. BIGINT HOUR(TIME time)
  2. BIGINT HOUR(TIMESTAMP timestamp)

入参

  • time

    TIME类型

  • timestamp

    TIMESTAMP类型

功能描述

返回输入时间参数time或timestamp中的24小时制的小时数,范围0~23。

示例

  • 测试数据
datetime1(VARCHAR) time1(VARCHAR) time2(TIME) timestamp1(TIMESTAMP)
2017-10-15 11:12:13 22:23:24 22:23:24 2017-10-15 11:12:13
  • 测试案例
  1. SELECT HOUR(TIMESTAMP '2016-09-20 23:33:33') as int1,
  2. HOUR(TIME '23:30:33') as int2,
  3. HOUR(time2) as int3,
  4. HOUR(timestamp1) as int4,
  5. HOUR(CAST(time1 AS TIME)) as int5,
  6. HOUR(CAST(datetime1 AS TIMESTAMP)) as int6
  7. FROM T1
  • 测试结果
int1(BIGINT) int2(BIGINT) int3(BIGINT) int4(BIGINT) int5(BIGINT) int6(BIGINT)
23 23 22 11 22 11