MySQL DAYNAME() Function
MySQL DAYNAME(): Return the Weekday Name for Any Date
The DAYNAME() function converts a DATE or DATETIME expression into the full name of its weekday, such as 'Monday' or 'Friday'. By default, it outputs English names, though it follows your session locale setting.
Operations teams use DAYNAME() to analyze which days of the week generate the highest order volume or support ticket spikes.
Syntax
Supply a single date or datetime value to DAYNAME():
DAYNAME(date_value)
date_value: ADATE,DATETIME,TIMESTAMP, or valid date string.
The return value is a string whose language depends on the lc_time_names session variable (default 'en_US').
Practical Example
Suppose your analytics team summarizes order counts by weekday across demo_orders to plan warehouse staffing.
SELECT
DAYNAME(order_date) AS weekday_name,
COUNT(*) AS order_count,
SUM(total_amount) AS revenue
FROM demo_orders
GROUP BY DAYNAME(order_date), DAYOFWEEK(order_date)
ORDER BY DAYOFWEEK(order_date);
| weekday_name | order_count | revenue |
|---|---|---|
| Sunday | 2 | 190.00 |
| Monday | 5 | 780.50 |
| Tuesday | 6 | 945.00 |
Notice that we sort by DAYOFWEEK(order_date) instead of weekday_name, ensuring Sunday through Saturday appear in calendar order rather than alphabetical order.
Common Mistakes & NULL Behavior
Avoid these common pitfalls when querying DAYNAME():
NULLand invalid dates returnNULL: CallingDAYNAME(NULL),DAYNAME('2026-02-30'), orDAYNAME('0000-00-00')producesNULL.- Alphabetical sorting trap: Running
ORDER BY DAYNAME(order_date)puts'Friday'first and'Wednesday'last. Always sort byWEEKDAY()orDAYOFWEEK(). - Locale-dependent output: If a connection sets
SET lc_time_names = 'es_ES';,DAYNAME()returns'lunes'instead of'Monday'. Do not hardcode English string comparisons inWHEREclauses without checkinglc_time_names; filter withDAYOFWEEK()orWEEKDAY()instead. - Standalone time strings fail: Passing
'11:20:00'without a calendar date evaluates toNULL.
Frequently Asked Questions
How do I get a 3-letter weekday abbreviation like 'Mon' or 'Tue'?
Use DATE_FORMAT(order_date, '%a') instead of DAYNAME(), which always returns the full weekday name.
Why is DAYNAME() case-insensitive in my WHERE clause?
MySQL string comparisons use the column or connection collation, which is case-insensitive (utf8mb4_0900_ai_ci) by default.
Does DAYNAME() accept a timestamp with time?
Yes. DAYNAME('2026-05-12 22:15:00') ignores the clock time and returns 'Tuesday'.
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.