LAST_DAY
Returns the date of the last day of the month for each date in a column.
Syntax
LAST_DAY( date )
Argument | Required/ Optional | Description |
---|
date | Required | Date/Time datatype. Passes the dates for which you want to return the last day of the month. You can enter any valid expression that evaluates to a date. |
Return Value
Date. The last day of the month for that date value you pass to this function.
NULL if a value in the selected column is NULL.
Null
If a value is NULL, LAST_DAY ignores the row. However, if all values passed from the column are NULL, LAST_DAY returns NULL.
Example
The following expression returns the last day of the month for each date in the ORDER_DATE column:
LAST_DAY( ORDER_DATE )
ORDER_DATE | RETURN VALUE |
---|
Apr 1 1998 12:00:00AM | Apr 30 1998 12:00:00AM |
Jan 6 1998 12:00:00AM | Jan 31 1998 12:00:00AM |
Feb 2 1996 12:00:00AM | Feb 29 1996 12:00:00AM (Leap year) |
NULL | NULL |
Jul 31 1998 12:00:00AM | Jul 31 1998 12:00:00AM |
You can nest TO_DATE to convert string values to a date. TO_DATE always includes time information. If you pass a string that does not have a time value, the date returned will include the time 00:00:00.
The following example returns the last day of the month for each order date in the same format as the string:
LAST_DAY( TO_DATE( ORDER_DATE, 'DD-MON-YY' ))
ORDER_DATE | RETURN VALUE |
---|
'18-NOV-98' | Nov 30 1998 00:00:00 |
'28-APR-98' | Apr 30 1998 00:00:00 |
NULL | NULL |
'18-FEB-96' | Feb 29 1996 00:00:00 (Leap year) |