This tutorial explains how to use the MySQL LAST_DAY function with syntax and examples.
The MySQL LAST_DAY function returns the last day of the month for a given date.
The syntax for the LAST_DAY function in MySQL is:
LAST_DAY( date_value )
The date or datetime value from which to extract the last day of the month.
The LAST_DAY function can be used in the following versions of MySQL:
Let's look at some MySQL LAST_DAY function examples and explore how to use the LAST_DAY function in MySQL.
For example:
mysql> SELECT LAST_DAY('2014-01-13');
Output: '2014-01-31'
mysql> SELECT LAST_DAY('2014-02-09 08:21:05');
Output: '2014-02-28'
mysql> SELECT LAST_DAY('2016-02-17');
Output: '2016-02-29'
mysql> SELECT LAST_DAY('2014-3-15');
Output: '2014-03-31'
mysql> SELECT LAST_DAY('AODBA.com: 2014-2-16');
Output: NULL
This last LAST_DAY example would display the last day of the month for the current system date (current system date is returned by the CURDATE function).
mysql> SELECT LAST_DAY(CURDATE());