Categories: Date/Time
WEEK
Extracts the ISO 8601 week number (from 1 to 53) for a given DATE or TIMESTAMP value. The week that contains the first Thursday of January is week 1. Returns NULL if the input is NULL.
Syntax
EXTRACT(WEEK FROM date_timestamp_expression string) → bigint
- date_timestamp_expression: A
DATEorTIMESTAMPexpression.
Examples
WEEK example using a timestampSELECT EXTRACT(WEEK FROM TIMESTAMP '2019-08-12 01:00:00.123456')
-- 33
SELECT EXTRACT(WEEK FROM DATE '2019-08-12')
-- 33
SELECT EXTRACT(WEEK FROM CAST('2019-08-12 01:00:00' AS TIMESTAMP))
-- 33
SELECT WEEK(DATE '2021-01-01')
-- 53
SELECT WEEK(DATE '2021-01-04')
-- 1
Usage Notes
This function uses the EXTRACT function. When using the CAST function, timestamps containing milliseconds are not allowed.