All Forums Teradata Debugger
RevathiS 5 posts Joined 08/16
18 Aug 2016
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...

dnoeth 4628 posts Joined 11/04
18 Aug 2016

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)

 

Dieter

RevathiS 5 posts Joined 08/16
18 Aug 2016

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

dnoeth 4628 posts Joined 11/04
19 Aug 2016

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

 

Dieter

You must sign in to leave a comment.