[MySQL] Get the number of days in a given month and year

Created on November 28, 2026

You can combine DAY() and LAST_DAY() to get the number of days in the month of a given date. LAST_DAY() returns the date of the last day of that month. DAY() extracts its day of the month, which gives you the total number of days in the month.

select day(last_day("2024-03-01"));

The query produces the following output.

+-----------------------------+
| day(last_day("2024-03-01")) |
+-----------------------------+
|                          31 |
+-----------------------------+
1 row in set (0.01 sec)
MySQL