WEEKDAY
WEEKDAY is a function in SQL that returns the index of the day in a week, given a date. The returned index follows the pattern where Monday is 0 and Sunday is 6.
WEEKDAY(date)
- date: The date or datetime value from which the day of the week is to be extracted. The accepted format is ‘YYYY-MM-DD’ or ‘YYYY-MM-DD HH
Example
SELECT WEEKDAY('2022-03-12');
Output
5
Explanation
The WEEKDAY function in MySQL returns the index of the weekday (0 = Monday, 1 = Tuesday, … 6 = Sunday). In the provided example, ‘2022-03-12’ falls on a Saturday hence, the output is 5.