Lesson

MySQL DAYNAME() Function

10 min reading
Free Course

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: A DATE, 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():

  • NULL and invalid dates return NULL: Calling DAYNAME(NULL), DAYNAME('2026-02-30'), or DAYNAME('0000-00-00') produces NULL.
  • Alphabetical sorting trap: Running ORDER BY DAYNAME(order_date) puts 'Friday' first and 'Wednesday' last. Always sort by WEEKDAY() or DAYOFWEEK().
  • 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 in WHERE clauses without checking lc_time_names; filter with DAYOFWEEK() or WEEKDAY() instead.
  • Standalone time strings fail: Passing '11:20:00' without a calendar date evaluates to NULL.

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'.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
MySQL Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum