Tuesday, May 22, 2012

Find current financial and Calendar Year in SQL Server

declare @d datetime
      set @d = GETDATE()
select
        DATEADD(yyyy, DATEDIFF(yyyy, 0, @d), 0) as [CalendarYear]
select
case
       when DATEPART(M, @d) >= 4 then DATEADD(mm, 3, DATEADD(yyyy, DATEDIFF(yyyy, 0, @d), 0))
        when DATEPART(M, @d) < 4 then DATEADD(mm, -9, DATEADD(yyyy, DATEDIFF(yyyy, 0, @d), 0))
end as [FinancialYear]

0 comments:

Post a Comment