Function Reference

MONTH

PostgreSQL equivalent:

Returns the month number of a date.

MySQL 8.1
MONTH(date)
date
Date or datetime
DATE

Return value

An integer from 1 to 12; 0 for a date with a zero month, for example 2022-00-00; NULL if the value is not recognized as a date

Examples

Month number from a date

MySQL 8.1
SELECT MONTH('2022-06-16');
MONTH('2022-06-16')
6

Payments per month

MySQL 8.1
SELECT MONTH(date) AS payment_month,
	COUNT(*) AS payments
FROM Payments
GROUP BY payment_month
ORDER BY payment_month;
payment_monthpayments
12
23
34
41
52
66
73
81
92
102

Details

The month does not include the year, so GROUP BY MONTH(date) merges Januaries of different years. To count by the months of each year, group by YEAR(date), MONTH(date) or by DATE_FORMAT(date, '%Y-%m').

See also