WEEK returns the week of the year in which the day is found, as an integer from 1 to 52, and where the first week of the year is 1.

Syntax

WEEK(expression)

Arguments

expression: a DATE, TIMESTAMP, or non-LONG VARCHAR string value that is properly formatted to represent a DATE or TIMESTAMP.

Returns

  • An INTEGER representing the week, between 1 and 52. Returns NULL when expression is NULL.

Examples

SELECT orderDate, WEEK(orderDate) AS orderDateWeek FROM MYSQL.inventory.cust;

VALUES WEEK(CAST('2012-01-01' AS TIMESTAMP))
-- Returns 1

VALUES WEEK(CAST('2012-12-31' AS TIMESTAMP))
-- Returns 52