LAST_DAY function - Amazon Redshift
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

LAST_DAY function

LAST_DAY returns the date of the last day of the month that contains date. The return type is always DATE, regardless of the data type of the date argument.

For more information about retrieving specific date parts, see DATE_TRUNC function.

Syntax

LAST_DAY( { date | timestamp } )

Arguments

date | timestamp

A column of data type DATE or TIMESTAMP or an expression that implicitly evaluates to a DATE or TIMESTAMP type.

Return type

DATE

Examples

The following example returns the date of the last day in the current month.

select last_day(sysdate); last_day ------------ 2014-01-31

The following example returns the number of tickets sold for each of the last 7 days of the month. The values in the SALETIME column are timestamps.

select datediff(day, saletime, last_day(saletime)) as "Days Remaining", sum(qtysold) from sales where datediff(day, saletime, last_day(saletime)) < 7 group by 1 order by 1; days remaining | sum ---------------+------- 0 | 10140 1 | 11187 2 | 11515 3 | 11217 4 | 11446 5 | 11708 6 | 10988 (7 rows)