Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 1.08 KB

File metadata and controls

38 lines (28 loc) · 1.08 KB
description
Extracts the hour number (from 0 to 23) for a given time or timestamp.

HOUR

Syntax

EXTRACT(HOUR FROM date_timestamp_expression string) → bigint

  • date_timestamp_expression: A TIME, TIMESTAMP, or DATE expression.

Examples

{% code title="HOUR example using a timestamp." %}

SELECT EXTRACT(HOUR FROM TIMESTAMP '2019-08-12 01:10:30.123456')
-- 1

{% endcode %}

{% code title="HOUR example using a time." %}

SELECT EXTRACT(HOUR FROM TIME '01:10:30.123456')
-- 1

{% endcode %}

{% code title="HOUR example using the CAST function." %}

SELECT EXTRACT(HOUR FROM CAST('2019-08-12 01:10:30' AS TIMESTAMP))
-- 1

{% endcode %}

Usage Notes

This function uses the EXTRACT function. When using the CAST function, timestamps containing milliseconds are not allowed.