Lesson

MySQL MONTHNAME() Function

10 min reading
Free Course

MySQL MONTHNAME() Function

The MySQL MONTHNAME() function returns the full English or locale-configured name of the month for a given DATE or DATETIME value. For example, '2026-05-10' returns 'May'.

Reports and customer-facing exports look cleaner when they display 'November' instead of 11. MONTHNAME() handles this conversion directly inside SQL without requiring a CASE statement or application-side lookup map.

Unlike MONTH(), which returns a number, MONTHNAME() returns a string and respects the lc_time_names session variable.

Syntax

MONTHNAME(date)
  • date: A DATE, DATETIME, TIMESTAMP, or valid date literal.

Practical Example

Suppose HR wants a list of employee hire months from demo_employees for 2025. Selecting both MONTH() and MONTHNAME() lets you display readable names while sorting in true calendar order.

SELECT
    MONTHNAME(hire_date) AS hire_month,
    COUNT(*) AS new_hires
FROM demo_employees
WHERE hire_date >= '2025-01-01'
  AND hire_date < '2026-01-01'
GROUP BY MONTH(hire_date), MONTHNAME(hire_date)
ORDER BY MONTH(hire_date);
hire_month new_hires
January 4
February 2
March 7

Sorting by MONTH(hire_date) ensures 'January' appears before 'February', rather than alphabetical order putting 'April' first.

Common Mistakes & NULL Behavior

Sorting directly by ORDER BY hire_month is a classic reporting bug. Alphabetical order puts 'April', 'August', and 'December' before 'January'. Always sort by MONTH(col) or DATE_FORMAT(col, '%Y-%m').

You should also watch ONLY_FULL_GROUP_BY mode. If you ORDER BY MONTH(hire_date) after grouping only by MONTHNAME(hire_date), MySQL raises a grouping error. Include MONTH(hire_date) in the GROUP BY clause as shown above.

MONTHNAME() returns NULL if date is NULL, invalid (such as '2026-02-30'), or has a zero month component like '2026-00-10'. Notice that '2026-00-10' returns 0 in MONTH(), but NULL in MONTHNAME() because month 0 has no name.

Frequently Asked Questions

How can I return abbreviated month names like 'Jan' or 'Feb'?

Use DATE_FORMAT(date, '%b') for three-letter month abbreviations. MONTHNAME() always returns the full month name.

How do I change the language returned by MONTHNAME()?

Set the session variable lc_time_names before your query, such as SET lc_time_names = 'es_ES'; for Spanish month names.

Does MONTHNAME() work in GROUP BY queries?

Yes, but if you want chronological sorting with ONLY_FULL_GROUP_BY enabled, group by both MONTH(col) and MONTHNAME(col).

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