LAST_DAY

LAST_DAY is an SQL function that returns the date of the last day of the month for a specific date provided. This function can be beneficial when you need to determine the end date of a month based on a given date.

LAST_DAY(date)

  • date: This parameter represents the date for which the function will find the last day of the month. It should be a DATE or an expression that can be evaluated to a DATE.

Example

SELECT LAST_DAY(TO_DATE('2022-01-01', 'YYYY-MM-DD')) AS Last_Day FROM dual;

Output

LAST_DAY
2022-01-31

Explanation

The LAST_DAY function returns the last day of the month for the provided date. In the example, the date ‘2022-01-01’ is provided, and the function returns ‘2022-01-31’, which is the last day of January.

LAST_DAY(date)

  • date: The date or datetime expression from which the last day of the month is to be returned. This parameter should be a valid date or datetime value from which the function can calculate the last day.

Example

SELECT LAST_DAY('2022-01-31') as LastDay;

Output

+------------+
| LastDay |
+------------+
| 2022-01-31 |
+------------+

Explanation

The LAST_DAY() function in this MySQL query returns the last day of the month for the provided date. In this example, the provided date is ‘2022-01-31’, and the last day of that month is ‘2022-01-31’. Therefore, the output is ‘2022-01-31’.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.