Total Pageviews

2015/09/21

[Oracle] How to get the last day of the month in Oracle

Requirement
If we would like to get the date of the last date of this month, does oracle have any build-in function?

How-To
Oracle has LAST_DAY function. The last day of the month is defined by the session parameter NLS_CALENDAR. The return type is always DATE, regardless of the datatype of date.

Example.
1
2
3
   SELECT to_char(sysdate, 'YYYYMMDD') "today",
          to_char(LAST_DAY(SYSDATE), 'YYYYMMDD') " last day of the month"
   FROM DUAL

Result:





Reference
[1] https://docs.oracle.com/cd/B28359_01/server.111/b28286/functions077.htm

No comments: