DAYOFWEEK returns the day of the week, as an integer from 1 to 7, where 1 is Sunday.

Syntax

DAYOFWEEK(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 day, between 1 and 7. Returns NULL when expression is NULL.

Examples

SELECT orderDate, DAYOFWEEK(orderDate) AS orderDateDay FROM MYSQL.inventory.cust;

VALUES DAYOFWEEK(CAST('2012-06-20'))
-- Returns 4

VALUES DAYOFWEEK(CAST('2012-06-03'))
-- Returns 1