MySQL: LAST_DAY Function

  • Post author:
  • Post category:MySQL
  • Post comments:1 Comment
MySQL LAST_DAY Function

In this guide, we will explain how to use the MySQL LAST_DAY function with syntax and examples.

Description

The MySQL LAST_DAY function returns the last day of the month for a given date.

Syntax

The syntax for the LAST_DAY function in MySQL is:

LAST_DAY( date_value )

Parameters or Arguments

date_value

The date or datetime value from which to extract the last day of the month.

Note

  • If date_value is not a valid date or datetime value, the LAST_DAY function would return NULL.

Applies To

The LAST_DAY function can be used in the following versions :

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1.1

Example

Let’s look at some LAST_DAY function examples and explore how to use the LAST_DAY function.

For example:

mysql> SELECT LAST_DAY('2014-01-13');
Result: '2014-01-31'

mysql> SELECT LAST_DAY('2014-02-09 08:21:05');
Result: '2014-02-28'

mysql> SELECT LAST_DAY('2016-02-17');
Result: '2016-02-29'

mysql> SELECT LAST_DAY('2014-3-15');
Result: '2014-03-31'

mysql> SELECT LAST_DAY('adglob.in: 2014-2-16');
Result: 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());

Next Topic : Click Here

This Post Has One Comment

Leave a Reply