0
0
MysqlHow-ToBeginner · 3 min read

How to Use MONTHNAME Function in MySQL: Syntax and Examples

In MySQL, use the MONTHNAME(date) function to get the full name of the month from a date or datetime value. It returns the month as a string like 'January' or 'February'.
📐

Syntax

The MONTHNAME() function takes one argument, which must be a date or datetime value. It returns the full name of the month as a string.

  • date: A date or datetime expression from which to extract the month name.
sql
MONTHNAME(date)
💻

Example

This example shows how to use MONTHNAME() to get the month name from a date column or a date literal.

sql
SELECT
  '2024-06-15' AS sample_date,
  MONTHNAME('2024-06-15') AS month_name;

-- Using a table example
CREATE TEMPORARY TABLE events (event_date DATE);
INSERT INTO events VALUES ('2024-01-10'), ('2024-12-25');
SELECT event_date, MONTHNAME(event_date) AS month_name FROM events;
Output
sample_date | month_name ------------|----------- 2024-06-15 | June event_date | month_name ------------|----------- 2024-01-10 | January 2024-12-25 | December
⚠️

Common Pitfalls

Common mistakes when using MONTHNAME() include:

  • Passing a string that is not a valid date format, which returns NULL.
  • Using numeric month values directly instead of a date or datetime type.
  • Expecting abbreviated month names; MONTHNAME() always returns the full month name.
sql
/* Wrong: Passing a number instead of a date */
SELECT MONTHNAME(6); -- Returns NULL

/* Right: Pass a valid date */
SELECT MONTHNAME('2024-06-01'); -- Returns 'June'
Output
NULL June
📊

Quick Reference

FunctionDescriptionExampleOutput
MONTHNAME(date)Returns full month name from dateMONTHNAME('2024-03-15')March
MONTH(date)Returns month number (1-12)MONTH('2024-03-15')3
DATE_FORMAT(date, '%b')Returns abbreviated month nameDATE_FORMAT('2024-03-15', '%b')Mar

Key Takeaways

Use MONTHNAME(date) to get the full month name from a date or datetime value.
Ensure the argument is a valid date or datetime; otherwise, MONTHNAME returns NULL.
MONTHNAME always returns the full month name, not abbreviated.
For abbreviated month names, use DATE_FORMAT with '%b'.
MONTHNAME is useful for readable date reports and grouping by month names.