MySQL DAYOFWEEK() Function
MySQL DAYOFWEEK(): Get the ODBC Weekday Index (1 = Sunday)
The DAYOFWEEK() function returns the weekday index for a date following the ODBC standard: 1 = Sunday, 2 = Monday, 3 = Tuesday, 4 = Wednesday, 5 = Thursday, 6 = Friday, and 7 = Saturday.
Scheduling and logistics queries use DAYOFWEEK() to separate weekend orders from Monday-through-Friday business days.
Syntax
Pass a single date or datetime value:
DAYOFWEEK(date_value)
date_value: ADATE,DATETIME,TIMESTAMP, or valid date string.
Unlike WEEKDAY() (which starts at 0 = Monday), DAYOFWEEK() is always 1-based and begins on Sunday.
Practical Example
Suppose your operations team inspects demo_orders to flag orders placed over the weekend (1 = Sunday or 7 = Saturday) for Monday morning dispatch.
SELECT
order_id,
order_date,
DAYNAME(order_date) AS day_label,
DAYOFWEEK(order_date) AS odbc_day_index
FROM demo_orders
WHERE DAYOFWEEK(order_date) IN (1, 7);
| order_id | order_date | day_label | odbc_day_index |
|---|---|---|---|
| 108 | 2026-05-09 | Saturday | 7 |
| 109 | 2026-05-10 | Sunday | 1 |
Checking IN (1, 7) reliably captures Saturday and Sunday regardless of your server's locale or lc_time_names setting.
Common Mistakes & NULL Behavior
Avoid these frequent errors with DAYOFWEEK():
- Assuming
1means Monday:DAYOFWEEK()follows ODBC rules where1is Sunday and2is Monday. If you expect0 = Mondaythrough6 = Sunday, useWEEKDAY()instead. NULLor invalid dates returnNULL: PassingNULL,'2026-02-30', or'0000-00-00'producesNULL.- Range comparisons for weekdays: Writing
DAYOFWEEK(order_date) <= 5includes Sunday (1) through Thursday (5), missing Friday (6)! UseBETWEEN 2 AND 6for Monday through Friday. - Confusing with
WEEK(date, mode): Changing thedefault_week_formatserver variable does not affectDAYOFWEEK(). It always uses1 = Sunday..7 = Saturday.
Frequently Asked Questions
What is the difference between DAYOFWEEK() and WEEKDAY()?
DAYOFWEEK() returns 1..7 with 1 = Sunday and 7 = Saturday. WEEKDAY() returns 0..6 with 0 = Monday and 6 = Sunday.
How do I filter Monday through Friday with DAYOFWEEK()?
Use WHERE DAYOFWEEK(order_date) BETWEEN 2 AND 6, because 2 is Monday and 6 is Friday.
Does DAYOFWEEK() change if my session locale changes?
No. DAYOFWEEK() always returns the fixed integer 1 (Sunday) through 7 (Saturday) in every locale.
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.