Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 1.07 KB

File metadata and controls

38 lines (28 loc) · 1.07 KB
description
Extracts the week number (from 0 to 53) for a given date or timestamp.

WEEK

Syntax

EXTRACT(WEEK FROM date_timestamp_expression string) → bigint

  • date_timestamp_expression: A DATE or TIMESTAMP expression.

Examples

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

SELECT EXTRACT(WEEK FROM TIMESTAMP '2019-08-12 01:00:00.123456')
-- 33

{% endcode %}

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

SELECT EXTRACT(WEEK FROM DATE '2019-08-12')
-- 33.

{% endcode %}

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

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

{% endcode %}

Usage Notes

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