Display Fiscal Year, Quarter and week in the quarter
At times we want to see what year, quarter or week in the quarter today or another date is.
The below query follows Oracle's fiscal year but should be easily modifiable to other fiscal years.
select 'FY' || substr((
case when extract(month from sysdate) > 5 then extract(year from sysdate)+1
else extract(year from sysdate) end), 3, 2) || 'Q' || (
case when extract(month from sysdate) between 1 and 2 then '3 Week ' || to_char(floor((sysdate - to_date(to_char(extract(year from sysdate)-1)||'-12-01', 'YYYY-MM-DD'))/7)+1)
when extract(month from sysdate) between 3 and 5 then '4 Week ' || to_char(floor((sysdate - to_date(to_char(extract(year from sysdate))||'-03-01', 'YYYY-MM-DD'))/7)+1)
when extract(month from sysdate) between 6 and 8 then '1 Week ' || to_char(floor((sysdate - to_date(to_char(extract(year from sysdate)-1)||'-06-01', 'YYYY-MM-DD'))/7)+1)
when extract(month from sysdate) between 9 and 11 then '2 Week ' || to_char(floor((sysdate - to_date(to_char(extract(year from sysdate)-1)||'-09-01', 'YYYY-MM-DD'))/7)+1)
when extract(month from sysdate) = 12 then '3 Week ' || to_char(floor((sysdate - to_date(to_char(extract(year from sysdate)-1)||'-11-01', 'YYYY-MM-DD'))/7)+1)
else 'something is wrong' end) fiscalinfo
from dual
Comments
Post a Comment