MySQL DAYOFWEEK() Function
In MySQL, the DAYOFWEEK()
function returns the weekday index of a given date.
DAYOFWEEK()
Syntax
Here is the syntax of MySQL DAYOFWEEK()
function:
DAYOFWEEK(expr)
Parameters
expr
- Required. A date or datetime expression.
Return value
The MySQL DAYOFWEEK()
function returns the weekday index of a given date. It returns a number 1
from to 7
, representing the weekday names as following:
1
- Sunday2
- Monday3
- Tuesday4
- Wednesday5
- Thursday6
- Friday7
- Saturday
If the specified expression is not a valid date or datetime, the DAYOFWEEK()
function will return NULL
.
If the argument is NULL
, the DAYOFWEEK()
function will return NULL
.
DAYOFWEEK()
Examples
Here are some examples of the DAYOFWEEK()
function.
SELECT
DAYOFWEEK('2022-02-21'),
DAYOFWEEK('2022-02-22'),
DAYOFWEEK('2022-02-23'),
DAYOFWEEK('2022-02-24'),
DAYOFWEEK('2022-02-25'),
DAYOFWEEK('2022-02-26'),
DAYOFWEEK('2022-02-27'),
DAYOFWEEK('2022-02-00'),
DAYOFWEEK('2022-02-30'),
DAYOFWEEK('Not A DATE'),
DAYOFWEEK(NULL)\G
DAYOFWEEK('2022-02-21'): 2
DAYOFWEEK('2022-02-22'): 3
DAYOFWEEK('2022-02-23'): 4
DAYOFWEEK('2022-02-24'): 5
DAYOFWEEK('2022-02-25'): 6
DAYOFWEEK('2022-02-26'): 7
DAYOFWEEK('2022-02-27'): 1
DAYOFWEEK('2022-02-00'): NULL
DAYOFWEEK('2022-02-30'): NULL
DAYOFWEEK('Not A DATE'): NULL
DAYOFWEEK(NULL): NULL