WEEKDAY
PostgreSQL equivalent:
Returns the weekday number of a date, counting from Monday as 0.
MySQL 8.1
WEEKDAY(date)Parameters
- dateDATE
- Date or datetime
Return value
An integer from 0 to 6, where 0 is Monday and 6 is Sunday; NULL for an incomplete date and for an unrecognized value
Examples
Monday and Sunday
MySQL 8.1
SELECT WEEKDAY('2024-01-01') AS monday,
WEEKDAY('2024-01-07') AS sunday;Payments by weekday
MySQL 8.1
SELECT WEEKDAY(date) + 1 AS weekday_from_monday,
COUNT(*) AS payments
FROM Payments
GROUP BY weekday_from_monday
ORDER BY weekday_from_monday;Details
The numbering differs from DAYOFWEEK, where the week starts on Sunday and counting starts at 1. WEEKDAY(date) + 1 gives the usual numbers from 1 (Monday) to 7 (Sunday). In PostgreSQL, the same is given by EXTRACT(ISODOW FROM date).