LAST_DAY()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Returns a date string representing the last day of the month specified by a DATE
or DATETIME
argument.
USAGE
LAST_DAY(date)
Argument Name | Description |
---|---|
| The |
DETAILS
LAST_DAY()
is date-time function that returns a date string representing the last day of the month for the specified date.The argument can be an actual
DATE
orDATETIME
type, a string in the formatYYYY-MM-DD
orYYYY-MM-DD hh:mm:ss
, or a numeric value in the formatYYYYMMDD
orYYYYMMDDhhmmss
.In string context the return value is a string with the format
YYYY-MM-DD
while in numeric context the return value is a number with the formatYYYYMMDD
.A
NULL
is returned if the argument isNULL
or otherwise invalid.
EXAMPLES
SELECT LAST_DAY('2018-02-01') AS 'Feb 2018',
LAST_DAY('2020-02-01 12:34:56') AS 'Feb 2020',
LAST_DAY(20200102) AS 'Jan 2020',
LAST_DAY(20201108123456) AS 'Nov 2020',
LAST_DAY('2020-02-30') AS 'Bad Day';
+------------+------------+------------+------------+---------+
| Feb 2018 | Feb 2020 | Jan 2020 | Nov 2020 | Bad Day |
+------------+------------+------------+------------+---------+
| 2018-02-28 | 2020-02-29 | 2020-01-31 | 2020-11-30 | NULL |
+------------+------------+------------+------------+---------+
SELECT CONCAT('The last day in February 1900 was: ',
LAST_DAY('1900-02-01') % 100) AS result;
+---------------------------------------+
| result |
+---------------------------------------+
| The last day in February 1900 was: 28 |
+---------------------------------------+