Returns the day of the week for a date value as an integer from 1 (Sunday) to 7 (Saturday).
Syntax
int dayofweek(datetime|timestamp|date|string <date>)Parameters
date: Required. A date value of the DATETIME, TIMESTAMP, DATE, or STRING type. The STRING value must include at least the yyyy-mm-dd part and must not contain extra characters. Accepted formats:
yyyy-mm-ddyyyy-mm-dd hh:mi:ssyyyy-mm-dd hh:mi:ss.ff3
Return value
Returns an INT value from 1 to 7. Returns null if the input is null, not one of the supported types, or does not match a supported format.
| Return value | Day |
|---|---|
| 1 | Sunday |
| 2 | Monday |
| 3 | Tuesday |
| 4 | Wednesday |
| 5 | Thursday |
| 6 | Friday |
| 7 | Saturday |
Examples
-- Returns 5 (Thursday)
SELECT dayofweek('2009-07-30');
-- Output: 5Related functions
DAYOFWEEK is a date function. For more information about functions related to date computing and conversion, see Date functions.