In this article, we will learn how to get a financial year using a given date in SQL Server.
Here is the code to get a financial year using a given date in SQL Server.
DECLARE @Financial_Year VARCHAR(20)
SELECT @Financial_Year = (CASE
WHEN (MONTH(GETDATE())) <= 3
THEN convert(varchar(4), YEAR(GETDATE())-1) + '-' + convert(varchar(4), YEAR(GETDATE())%100)
ELSE convert(varchar(4),YEAR(GETDATE()))+ '-' + convert(varchar(4),(YEAR(GETDATE())%100)+1)
END)
SELECT @Financial_Year AS 'Financial Year'
Financial Year
--------------------
2019-20
(1 row(s) affected)
I hope this article will help you to understand how to get a financial year using a given date in SQL Server.
Share your valuable feedback, please post your comment at the bottom of this article. Thank you!
Comments