MySQL 8.1
QUARTER(date)Parameters
- dateDATE
- Date or datetime
Return value
An integer from 1 to 4; 0 for a date with a zero month; NULL if the value is not recognized as a date
Examples
Quarter of a date
MySQL 8.1
SELECT QUARTER('2022-06-16');Payments per quarter
MySQL 8.1
SELECT QUARTER(date) AS payment_quarter,
COUNT(*) AS payments
FROM Payments
GROUP BY payment_quarter
ORDER BY payment_quarter;Details
The quarter does not include the year, so GROUP BY QUARTER(date) merges the first quarters of different years. To count by the quarters of each year, group by YEAR(date), QUARTER(date).