Skip to main content

How to get first and last date of the quarter?

  • Dec 7, 2015 8:01 PM UTC
  • 4 replies
  • 19 views

David_P_1
Forum|alt.badge.img+2

How can I get the first and last date of the quarter?

4 replies

NorbertK
Forum|alt.badge.img
  • Participating Frequently
  • Dec 7, 2015 8:39 PM UTC

Quarter can mean different things for different people. Have you tried anything?


David_P_1
Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • Dec 7, 2015 9:18 PM UTC

Today is 2015-12-07.  For us the first date of the quarter would be 2015-10-01.

 

I tried this: 

select year(sysdate) || '-' || (quarter(sysdate)-1)*3+1 || '-' || '01' 

result: 2015-10-01

 

My way was succesful, I was wondering if there is a better way.


David_P_1
Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • Dec 7, 2015 9:39 PM UTC

The last date of the quarter would be 2015-12-31.

 

I tried this:

select date(year(date(current_date - EXTRACT(DOQ FROM CURRENT_DATE) + 1) + 100) || '-' || month(date(current_date - EXTRACT(DOQ FROM CURRENT_DATE) + 1) + 100) || '-' || '01') - 1

 

Result 2015-12-31

 

Result is successful, but method is a bit convoluted.


Oleg_Savkin
Forum|alt.badge.img
  • Participating Frequently
  • Jan 13, 2017 12:58 AM UTC

SELECT ADD_MONTHS(TRUNC( current_date, 'Q'), 3)-1;