Skip to main content
Version: current [24.3.x]

WEEK

Categories: Date/Time

WEEK

Extracts the week number (from 0 to 53) for a given date or timestamp.

Syntax

EXTRACT(WEEK FROM date_timestamp_expression string) → bigint

  • date_timestamp_expression: A DATE or TIMESTAMP expression.

Examples

WEEK example using a timestamp
SELECT EXTRACT(WEEK FROM TIMESTAMP '2019-08-12 01:00:00.123456')
-- 33
WEEK example using a date
SELECT EXTRACT(WEEK FROM DATE '2019-08-12')
-- 33
WEEK example using the CAST function
SELECT EXTRACT(WEEK FROM CAST('2019-08-12 01:00:00' AS TIMESTAMP))
-- 33

Usage Notes

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