MySQL LAST_DAY() Function

The LAST_DAY() function in MySQL is used to determine the last day of the month for a given date. This is particularly useful for generating reports, performing date-based calculations, or filtering data based on monthly intervals.



LAST_DAY(): Definition and Usage

This function simplifies working with monthly data. It takes a date value as input and returns the date of the last day of the month that contains that date. The output is always the last day of the month, regardless of the day provided as input. The output format matches the input format.

Syntax

Syntax

LAST_DAY(date)
      

Parameter Values

Parameter Description
date The date value. This is required.

Examples

Finding the Last Day of a Month

This example shows how to find the last day of June 2017.

Syntax

SELECT LAST_DAY("2017-06-20");
      
Output

2017-06-30
      

Finding the Last Day of a Month from a DateTime Value

This example shows that LAST_DAY() works correctly with datetime values, extracting the last day of the month regardless of the time portion.

Syntax

SELECT LAST_DAY("2017-02-10 09:34:00");
      
Output

2017-02-28