Function Reference

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');
LAST_DAY('2024-02-10')
2024-02-29

End of the month for payments

MySQL 8.1
SELECT date,
	LAST_DAY(date) AS month_end
FROM Payments;
datemonth_end
2005-02-122005-02-28
2005-03-232005-03-31
2005-05-142005-05-31
2005-07-222005-07-31
2005-07-262005-07-31
2005-02-202005-02-28
2005-07-302005-07-31
2005-09-122005-09-30
2005-09-302005-09-30
2005-10-272005-10-31

Number of days in a month

MySQL 8.1
SELECT DAY(LAST_DAY('2023-02-10')) AS days_in_month;
days_in_month
28

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'.

See also