Oracle - LAST_DAY Function - Get Last Date of Month

LAST_DAY function returns date (not just day) where the day is set to the last day of the month.

Quick Example:

Get the last date of the current month (SYSDATE returns January 11, 2012 in this example):

   SELECT LAST_DAY(SYSDATE) FROM dual;
   -- Result: January 31, 2012

LAST_DAY Overview

Summary information:

Syntax LAST_DAY(datetime_expression)
Return Type DATE

Last Update: Oracle 11g Release 2

LAST_DAY Details

LAST_DAY function returns the last date of the specified month in the input datetime expression:

    -- Set default datetime format in string literals
    ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MM-YYYY';
 
    -- Get last date in January 2012
    SELECT LAST_DAY('11-01-2012') FROM dual;
    -- Result: 31-01-2012

Get Last Day

LAST_DATE function returns date, and you can use EXTRACT function to get day:

   SELECT EXTRACT(DAY FROM LAST_DAY('11-01-2012')) FROM dual;
   -- Result: 31

Oracle Resources

Oracle 11g Release 2 SQL Language Reference