How can I get the first and last date of the quarter?
Quarter can mean different things for different people. Have you tried anything?
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.
The last date of the quarter would be 2015-12-31.
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.
SELECT ADD_MONTHS(TRUNC( current_date, 'Q'), 3)-1;
Comments
Quarter can mean different things for different people. Have you tried anything?
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.
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.
SELECT ADD_MONTHS(TRUNC( current_date, 'Q'), 3)-1;