The LAST_DAY() function is used to extract the last day of the month for a given date.
Definition and Usage
- The
LAST_DAY()function returns the last day of the month for a givenDATEorDATETIMEvalue.
Syntax
LAST_DAY(date)
- date: Required. A valid date or datetime value from which the last day of the month is to be extracted.
Examples
Example 1: Extract the last day of the month for a given DATE
SELECT LAST_DAY("2017-06-20");
Output:
2017-06-30
This example returns 2017-06-30 because it's the last day of June 2017.
Example 2: Extract the last day of the month for a DATETIME
SELECT LAST_DAY("2017-02-10 09:34:00");
Output:
2017-02-28
This example returns 2017-02-28 because February 2017 has 28 days.
Technical Details
- Works in MySQL versions: From MySQL 4.0.
- Return type: The function returns a
DATEvalue representing the last day of the month.