MySQL WEEKDAY() Function
MySQL WEEKDAY() Function
The MySQL WEEKDAY() function returns the weekday index for a DATE or DATETIME value as an integer from 0 to 6, where 0 is Monday and 6 is Sunday.
Zero-based Monday indexing makes WEEKDAY() natural for business-day logic: weekdays (MondayβFriday) are simply 0 through 4, while weekends (Saturday and Sunday) are 5 and 6. You can also compute Monday of the current week cleanly with DATE_SUB(col, INTERVAL WEEKDAY(col) DAY).
Do not confuse WEEKDAY() with DAYOFWEEK(), which uses 1 for Sunday through 7 for Saturday.
Syntax
WEEKDAY(date)
date: ADATE,DATETIME,TIMESTAMP, or valid date literal.
Practical Example
In demo_orders, you can separate weekday orders from weekend orders using a concise WEEKDAY() check.
SELECT
order_id,
order_date,
WEEKDAY(order_date) AS weekday_idx,
CASE
WHEN WEEKDAY(order_date) >= 5 THEN 'Weekend'
ELSE 'Business Day'
END AS day_type
FROM demo_orders
WHERE order_date BETWEEN '2026-05-08' AND '2026-05-10'
ORDER BY order_date;
| order_id | order_date | weekday_idx | day_type |
|---|---|---|---|
| 1301 | 2026-05-08 | 4 | Business Day |
| 1302 | 2026-05-09 | 5 | Weekend |
| 1303 | 2026-05-10 | 6 | Weekend |
Friday (2026-05-08) returns 4, Saturday returns 5, and Sunday returns 6.
Common Mistakes & NULL Behavior
The most frequent bug is mixing up WEEKDAY() and DAYOFWEEK(). Remember this mapping:
WEEKDAY():0= Monday,1= Tuesday, ...,5= Saturday,6= Sunday.DAYOFWEEK():1= Sunday,2= Monday, ...,7= Saturday.
If you port code from DAYOFWEEK() and forget to adjust the index, WEEKDAY(d) = 1 filters Tuesdays instead of Sundays! Also remember WEEKDAY() is never affected by default_week_format or lc_time_names; Monday is always 0.
WEEKDAY() returns NULL if date is NULL, invalid (like '2026-02-30'), or '0000-00-00'.
Frequently Asked Questions
How do I find the Monday of any given date's week?
Subtract WEEKDAY(date) days: DATE_SUB(date, INTERVAL WEEKDAY(date) DAY). Because Monday has index 0, subtracting 0 days keeps Mondays unchanged.
Which is faster: WEEKDAY() or DAYNAME()?
Both take negligible CPU per row, though WEEKDAY() returns a tiny integer (0β6) that is much cleaner for numeric CASE expressions and comparisons than English strings.
Does WEEKDAY() ever return 7?
No. Its valid range is strictly 0 through 6.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.