calculate fiscal year in sql select statement?

后端 未结 10 1370
谎友^
谎友^ 2020-12-19 05:10

I have a date field that needs to return in fiscal year format. example

Start_Date        Year 
04/01/2012 -      2013
01/01/2012 -      2012
09/15/2013 -            


        
10条回答
  •  自闭症患者
    2020-12-19 06:10

    I just chose to do it this way. It's easy and you can replace the 09,30 with whatever you want your fiscal year end to be. Not sure if this works in anything but SQL Server though.

    CASE 
        WHEN CAST(GETDATE() AS DATE) > 
             SMALLDATETIMEFROMPARTS(DATEPART(YEAR,GETDATE()),09,30,00,000) 
        THEN 
            DATEPART(YEAR,GETDATE()) + 1 ELSE DATEPART(YEAR,GETDATE()) 
        END AS FY
    

提交回复
热议问题