Skip to content
Advertisement

Fiscal year from getdate in SQL

I need to get the fiscal year from getdate(). My fiscal year format should be if getdate is today(18/03/2022) then the fiscal year column should show ‘FY22’ I used the below query to get the fiscal year Query Used:

enter image description here

Advertisement

Answer

Add 6 months to the date (getdate in your example), then take the righmost two digits of the year, and concatenate ‘FY’ in front of it The actual expression is rdbms dependent -you have not tagged; but for SQLServer:

'FY'+right(cast(year(dateadd(month,6,getdate())) as char(4)), 2)

or, using a relatively recent FORMAT function making use of format providers in the Microsoft .Net library (https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings):

select format(dateadd(month,6,getdate()),'FYyy')

Backslash characters cause the function to ignore any special formatting code meaning of the letters F and Y, and hence F and Y are simply passed on to the output, the remaining yy is a format specifier for two digit years.

This is, of course, if your fiscal year runs from 1-Jul to 30-Jun.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement