MONTH() in MySQL — How It Works
What the MySQL MONTH() function does, with an example.
Published October 20, 2026
MONTH(date) returns the month number (1–12). MONTHNAME() returns the name.
How it works
Combine with YEAR for monthly reports.
Try it in MySQL
SELECT MONTH('2026-11-12')
11
SELECT MONTHNAME('2026-11-12')
November
SELECT YEAR(d), MONTH(d), SUM(total) FROM orders GROUP BY 1, 2
monthly totals
Practical examples
Example 1
SELECT MONTH('2026-11-12');
-- 11Example 2
SELECT MONTHNAME('2026-11-12');
-- NovemberExample 3
SELECT YEAR(d), MONTH(d), SUM(total) FROM orders GROUP BY 1, 2;
-- monthly totalsUse it in a real query
SELECT id, MONTH('2026-11-12') AS result
FROM your_table
LIMIT 10;Common mistakes
- Grouping by MONTH alone across years.
- Using in WHERE on indexed columns.
- Zero month values from invalid dates.
Key takeaways
- MONTH() in one line: MONTH(date) returns the month number (1–12).
- Try queries in a test database first.
- Check NULL handling and data types.
FAQ
Group by month?
Group by YEAR and MONTH (or DATE_FORMAT '%Y-%m').
Does MONTH() work in other databases?
Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.