Date and quarter SQL ORACLE

Soji picture Soji · Jul 22, 2015 · Viewed 10.9k times · Source

I am currently working on oracle sql and have some issues managing dates and quarters.

The first thing I try to do is given a quarter and a year I would like to know the number of days of the quarter. For example, quarter 1 in 2013 had 90 days but in 2012 had 91 days.

The second thing I would like to do is convert a date dd/qq/yyyy to a date dd/mm/yyyy.

For instance, 60/2/2013 gives 30/5/2013. I am a beginner in Oracle so any help or function names will be highly appreciated.

Thanks

Answer

davegreen100 picture davegreen100 · Jul 22, 2015

this gives the number of days in the current quarter, playing around with the add_months should allow you to find the length of other quarters

select (add_months(trunc(sysdate,'q'),3) - 1) - trunc(sysdate,'q') 
from dual;