MySQL LAST_DAY Function

MySQL LAST_DAY function is one of the MySQL Date Functions, which returns the last day of the month from the given date. Let us see how to use this LAST_DAY function to get the last day in a month in MySQL from an expression with an example. The basic syntax of the LAST_DAY() Function in MySQL is as shown below:

LAST_DAY(date or expression);

MySQL LAST_DAY function Example

These MySQL examples help you understand the use of last day function. Here, we are returning the last day of the month from different date expressions.

SELECT LAST_DAY('2017-01-01');

SELECT LAST_DAY('2018-06-14');

SELECT LAST_DAY('2018-09-14');
MySQL LAST_DAY Function 1

Let us see another example of the MySQL LAST DAY function. Here, we are returning the last day of the month from the current date and time returned by the Now() and CURDATE() function.

SELECT LAST_DAY(NOW()), LAST_DAY(CURRENT_DATE());
MySQL LAST_DAY Function 2

MySQL LAST_DAY Function Example 2

The following Date Function queries show you what happens when we try to return the day of year value from string date or invalid dates.

SELECT LAST_DAY(NOW() + 22);

SELECT LAST_DAY('2018-06-32');

SELECT LAST_DAY(CURDATE() + 22);
MySQL LAST_DAY Function 3

From the above screenshot, LAST_DAY(‘2018-06-32’); statement returned NULL. Because it’s an invalid MySQL date. Within the Last statement, LAST_DAY(CURDATE() + 22); means, LAST_DAY(‘2019-02-33’);. Again, it’s an invalid date.