MySQL WEEKDAY() Function
In MySQL, the WEEKDAY()
function returns the weekday index for a given date.
WEEKDAY()
Syntax
Here is the syntax of MySQL WEEKDAY()
function:
WEEKDAY(date)
Parameters
date
- Required. A date or datetime expression.
Return value
The MySQL WEEKDAY()
function returns the weekday index for a given date, in the range from 0
to 6
, as following:
0
- Monday1
- Tuesday2
- Wednesday3
- Thursday4
- Friday5
- Saturday6
- Sunday
If the specified expression is not a valid date or datetime, the WEEKDAY()
function will return NULL
.
If the argument is NULL
, the WEEKDAY()
function will return NULL
.
WEEKDAY()
Examples
Here are some examples of the WEEKDAY()
function.
SELECT
WEEKDAY('2022-02-21'),
WEEKDAY('2022-02-22'),
WEEKDAY('2022-02-23'),
WEEKDAY('2022-02-24'),
WEEKDAY('2022-02-25'),
WEEKDAY('2022-02-26'),
WEEKDAY('2022-02-27')\G
WEEKDAY('2022-02-21'): 0
WEEKDAY('2022-02-22'): 1
WEEKDAY('2022-02-23'): 2
WEEKDAY('2022-02-24'): 3
WEEKDAY('2022-02-25'): 4
WEEKDAY('2022-02-26'): 5
WEEKDAY('2022-02-27'): 6
To return today’s weekday index, use NOW()
, or CURDATE()
, or CURRENT_DATE()
, or SYSDATE()
. For example:
SELECT
WEEKDAY(NOW()),
WEEKDAY(CURDATE()),
WEEKDAY(CURRENT_DATE()),
WEEKDAY(SYSDATE())\G
WEEKDAY(NOW()): 5
WEEKDAY(CURDATE()): 5
WEEKDAY(CURRENT_DATE()): 5
WEEKDAY(SYSDATE()): 5