Fetching the last date of the current Quarter !!!

Teradata Debugger
Enthusiast

Fetching the last date of the current Quarter !!!

Fetching the last date of the current Quarter !!! 

This query fetches the fist date of the current Quarter-->>select TRUNC(ADD_MONTHS(CURRENT_DATE,-1),'Q').

Need to know the last date of the current Quarter.. Tried of getting like select ADD_MONTHS(DATE,+1) but here i dont know to proceed with the quarter..

Kndly help me with this...

3 REPLIES
Senior Apprentice

Re: Fetching the last date of the current Quarter !!!

Your first calculation doesn't return the current quarter correctly, e.g. in July it will return 2016-04-01 instead of 2016-07-01.

-- begin of current quarter
trunc(current_date, 'q')

-- end of current quarter
trunc(add_months(current_date,3), 'q') -1
-- or
oAdd_months(trunc(current_date, 'q')-1, 3)
Enthusiast

Re: Fetching the last date of the current Quarter !!!

Hi Dieter,

           Yeah its working for the end of current quarter. Thank you. The code for fetching the current quarter's first date is working fine.  If i am wrong please correct me further..

 select TRUNC(ADD_MONTHS(CURRENT_DATE,-1),'Q').

7/1/2016

Senior Apprentice

Re: Fetching the last date of the current Quarter !!!

If you consider this correct:

SELECT TRUNC(ADD_MONTHS(DATE '2016-10-20',-1),'Q');

*** Query completed. One row found. One column returned.
*** Total elapsed time was 1 second.

TRUNC(ADD_MONTHS(2016-10-20, -1),'Q')
-------------------------------------
2016-07-01