The PLSQL LAST_DAY function is used for returning the last day of the month based on a date value. The last day of the month is defined by the session parameter NLS_CALENDAR.
The LAST_DAY function accepts one parameter which is the date value used to calculate the last day of the month. The LAST_DAY function returns a value of the DATE datatype, regardless of the datatype of date.
Syntax:
LAST_DAY(date)
Parameters Used:
date – It is used to specify the date value used to calculate the last day of the month.
Return Value:
The LAST_DAY function in PLSQL returns a DATE type value.
Supported Versions of Oracle/PLSQL:
- Oracle 12c
- Oracle 11g
- Oracle 10g
- Oracle 9i
- Oracle 8i
Example-1: Getting the last day of the current month.
SELECT LAST_DAY(SYSDATE) FROM dual;
Output:
31.10.19
Example-2: Getting the last day of a specific month.
SELECT
LAST_DAY(TO_DATE('2003/02/12', 'yyyy/mm/dd'))
FROM
dual;
Output:
Feb 28, 2003
Example-3: Returning the number of days left of the current month.
SELECT LAST_DAY( SYSDATE ) - SYSDATE FROM dual;
Output:
2
The system considers 29th October 2019 as the current date while the article was written. It may vary from user to user.
Example-4: Returning the last day of the previous month.
SELECT LAST_DAY(ADD_MONTHS(SYSDATE, -1 )) FROM dual;
Output:
30.09.19
The system considers 29th October 2019 as the current date while the article was written. It may vary from user to user.
Example-5: Returning the last day of the next month.
SELECT LAST_DAY(ADD_MONTHS(SYSDATE, 1 )) FROM dual;
Output:
30.11.19
The system considers 29th October 2019 as the current date while the article was written. It may vary from user to user.
Recommended Posts:
- PLSQL | MOD Function
- PLSQL | EXP Function
- PLSQL | LEAST Function
- PLSQL | LN Function
- PLSQL | TAN Function
- PLSQL | ABS Function
- PLSQL | LOG Function
- PLSQL | CHR Function
- PLSQL | COS Function
- PLSQL | SIN Function
- PLSQL | SQRT Function
- PLSQL | POWER Function
- PLSQL | REMAINDER Function
- PLSQL | INSTRB Function
- PLSQL | CURRENT_DATE Function
- PLSQL | ADD_MONTHS Function
- PLSQL | LENGTH Function
- PLSQL | CURRENT_TIMESTAMP Function
- PLSQL | SUBSTR Function
- PLSQL | ATAN Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


