Basic Logics · Date Functions · Real Scenario Logic's

To Find Current Indian Financial Year Start and End Date easily in both Azure SQL and On-Premises

Introduction

The main objective of this post is let the users to know, how we can find Indian Financial Year Start and End Date easily in both Azure SQL and On-Premises with the common simple script. The below suggested script would work for both Azure SQL and On-Premises.

Financial Year

A Financial Year is actually the period between 1st April and 31st March – the year in which you earn an income.

Logic

To know Common Datetime that works well in both Azure and On-premises, Please check my previous blogpost named – ‘ AZURE Current DateTime ‘.

  1. We need to find the current month by using the current date that is common for both AZURE and On-Premises.
  2. If current month is before ‘APRIL’, then the financial year we need to look for is previous year.Or else Current Year.
  3. Then, we can take Start date as 1st April(Year is result of #2) and End date as 31st March(Year+1 is result of #2).

SQL Script

DECLARE @Current_DateTime DATETIME= SYSDATETIMEOFFSET() AT TIME ZONE 'India Standard Time'; -- GETDATE()
--	SET @Current_DateTime='20200312'; -- uncomment this line to test with your desired date.

SELECT DATEFROMPARTS(Yr, 4, 1) AS FinancialYear_StartDate,
DATEFROMPARTS(Yr + 1, 3, 31) AS FinancialYear_EndDate,
CONCAT(Yr,'-',Yr+1) AS FinancialYear
FROM 
(SELECT CASE WHEN DATEPART(MONTH, @Current_DateTime ) < 4 
THEN DATEPART(YEAR, @Current_DateTime ) - 1 ELSE DATEPART(YEAR, @Current_DateTime ) END Yr) a;

Image Pic

Execution Plan

Conclusion

Thus, we can use the above script to find the Indian Financial Year Start and End Dates easily in SQL Server. The above Script is unit tested in both Azure SQL db and on-premises.

Thanks for reading!

FOLLOW BLOG for interesting upcoming posts!

Advertisement

One thought on “To Find Current Indian Financial Year Start and End Date easily in both Azure SQL and On-Premises

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s