MySQL LAST_DAY is one of the Date Functions, which returns the last day of the month from the given date. Let us see how to use this MySQL LAST_DAY function to get the last day in a month from an expression with an example, and the basic syntax of this is as shown below:
LAST_DAY(date or expression);
MySQL LAST_DAY function Example
These examples help you understand the use of last day method. 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');
Let us see another example of the LAST DAY function. Here, we are returning the last day of the month from the current datetime returned by the Now() and CURDATE() methods available in Date method.
SELECT LAST_DAY(NOW()), LAST_DAY(CURRENT_DATE());
LAST_DAY Example 2
The following MySQL LAST_DAY Function queries show you what happens when we try to return the day of year value from string or invalid dates.
SELECT LAST_DAY(NOW() + 22);
SELECT LAST_DAY('2018-06-32');
SELECT LAST_DAY(CURDATE() + 22);
From the above screenshot, (‘2018-06-32’); statement returned NULL. Because it’s an invalid MySQL dt. Within the Last statement, (CURDATE() + 22); means, (‘2019-02-33’);. Again, it’s an invalid dt.