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 month number (from 1 to 12) for a given date or timestamp.

MONTH

Syntax

EXTRACT(MONTH FROM date_timestamp_expression string) → bigint

  • date_timestamp_expression: A DATE or TIMESTAMP expression.

Examples

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

SELECT EXTRACT(MONTH FROM TIMESTAMP '2019-08-12 01:00:00.123456')
-- 8

{% endcode %}

{% code title="MONTH example using a date." %}

SELECT EXTRACT(MONTH FROM DATE '2019-08-12')
-- 8

{% endcode %}

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

SELECT EXTRACT(MONTH FROM CAST('2019-08-12 01:00:00' AS TIMESTAMP))
-- 8

{% endcode %}

Usage Notes

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