MySQL 8.1
MONTH(date)- date
- Date or datetimeDATE
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');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;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').