Skip to main content
Version: Latest-3.2

last_day

Description

Returns the last day of an input DATE or DATETIME expression based on the specified date part. For example, last_day('2023-05-10', 'month') returns the last day of the month in which '2023-05-10' falls.

If the date part is not specified, this function returns the last day of the month for a given date.

This function is supported from v3.1.

Syntax

DATE last_day(DATETIME|DATE date_expr[, VARCHAR unit])

Parameters

  • date_expr: a DATE or DATETIME expression, required.

  • unit: the date part, optional. Valid values include month, quarter, and year, default to month. If unit is invalid, an error is returned.

Return value

Returns a DATE value.

Examples

MySQL > select last_day('2023-05-10', 'month');
+----------------------------------+
| last_day('2023-05-10', 'month') |
+----------------------------------+
| 2023-05-31 |
+----------------------------------+

MySQL > select last_day('2023-05-10');
+------------------------+
| last_day('2023-05-10') |
+------------------------+
| 2023-05-31 |
+------------------------+

MySQL > select last_day('2023-05-10', 'quarter');
+-----------------------------------+
| last_day('2023-05-10', 'quarter') |
+-----------------------------------+
| 2023-06-30 |
+-----------------------------------+

MySQL > select last_day('2023-05-10', 'year');
+---------------------------------------+
| last_day('2023-05-10', 'year') |
+---------------------------------------+
| 2023-12-31 |
+---------------------------------------+

keyword

LAST_DAY, LAST