Skip to content

Instantly share code, notes, and snippets.

@tsnoad
Last active December 14, 2015 00:48
Show Gist options
  • Save tsnoad/5001308 to your computer and use it in GitHub Desktop.
Save tsnoad/5001308 to your computer and use it in GitHub Desktop.
get financial year from a date in oracle
with dates as (
select sysdate-240 as sometime from dual
union select sysdate-180 as sometime from dual
union select sysdate-120 as sometime from dual
union select sysdate-60 as sometime from dual
union select sysdate as sometime from dual
union select sysdate+60 as sometime from dual
union select sysdate+120 as sometime from dual
union select sysdate+180 as sometime from dual
union select sysdate+240 as sometime from dual
union select to_date('2013-06-30', 'YYYY-MM-DD') as sometime from dual
union select to_date('2013-07-01', 'YYYY-MM-DD') as sometime from dual
)
select
sometime,
'FY'||to_char(
extract(year from sometime)
+floor((extract(month from sometime)-1)/6)
) as financial_year
from dates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment