LAST_DAY
Returns the last day of the month for the given date.
MySQL 8.1
LAST_DAY(date)Parameters
- dateDATE
- Date or datetime
Return value
A date (DATE) that accounts for leap years; NULL if the value is not recognized as a date
Examples
End of the month for a date
MySQL 8.1
SELECT LAST_DAY('2024-02-10');End of the month for payments
MySQL 8.1
SELECT date,
LAST_DAY(date) AS month_end
FROM Payments;Number of days in a month
MySQL 8.1
SELECT DAY(LAST_DAY('2023-02-10')) AS days_in_month;Details
The first day of a month comes from the last day of the previous month: LAST_DAY(date - INTERVAL 1 MONTH) + INTERVAL 1 DAY. PostgreSQL has no such function; the last day of the month is calculated there as DATE_TRUNC('month', date) + INTERVAL '1 month - 1 day'.