SQL for last year starting and ending dates

Database
Enthusiast

SQL for last year starting and ending dates

Hi all,

I am trying to get SQL for last year starting and ending dates.

Ex : 01/01/2012 & 12/31/2012.

3 REPLIES
Enthusiast

Re: SQL for last year starting and ending dates

That would be very close to what I wrote to your question for THIS year's starting and ending date, just that you need to subtract 1 from the year number:

select
cast( trim( extract( year from current_date ) - 1 ) || '-01-01' as DATE )
as first_day_of_previous_year,
cast( trim( extract( year from current_date ) - 1 ) || '-12-31' as DATE )
as last_day_of_previous_year;

Re: SQL for last year starting and ending dates

select min(calendar_date) starting, max(calendar_date) ending from sys_calendar.calendar where
year_of_calendar=2013

This will display the Start & End date of the year 2013
Highlighted
Enthusiast

Re: SQL for last year starting and ending dates

The starting dates and end dates for a year are constant, why would you waste cpu cycles trying find max/min.  The year always starts with January 1 and ends with December 31.  If its a leap year you might have an additional date stuck in between (February 29), but the endpoints are always, until some Pope decides to change the calendar again....:-)