This topic describes how to use the date function HOUR in Realtime Compute.

Syntax

BIGINT HOUR(TIME time)
BIGINT HOUR(TIMESTAMP timestamp)    

Input parameters

Parameter Data type
time TIME
timestamp TIMESTAMP

Description

Returns the number of hours (in the 24-hour format) in the specified time or timestamp value. The return value ranges from 0 to 23.

Example

  • Test data
    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
  • Test statements
    SELECT HOUR(TIMESTAMP '2016-09-20 23:33:33') AS int1,
     HOUR(TIME '23:30:33') AS int2,
     HOUR(time2) AS int3,
     HOUR(timestamp1) AS int4,
     HOUR(CAST(time1 AS TIME)) AS int5,
     HOUR(TO_TIMESTAMP(datetime1)) AS int6
    FROM T1;              
  • Test results
    int1 (BIGINT) int2 (BIGINT) int3 (BIGINT) int4 (BIGINT) int5 (BIGINT) int6 (BIGINT)
    23 23 22 11 22 11