Sometimes we need to get the last day of month in mysql because every month has different last day eg. FEB. may have 28 or 29, JAN has 31 and APR has 30.
MySQL provide us a function LAST_DAY()
returns the last day of the corresponding month for a date or datetime value. If the date or datetime value is invalid, the function returns NULL.
SYNTAX :
1 | LAST_DAY(specificdate) |
Here specificdate is any valid date.
Example :
The following statement will return the last date of the corresponding month of the given date 2014-10-09.
1 2 3 4 | SELECT LAST_DAY('2014-10-09'); Output would be 2014-10-31 |
2.
The following statement will return the last date of the corresponding month of the given datetime 2014-10-09 15:45:53.
1 2 3 4 | SELECT LAST_DAY('2014-10-09 15:45:53'); Output would be 2014-10-31 |
Last_Day() is an easy function to get last day of month in mysql.