How To Find Indian Financial Year And Financial Quarter From A Particular Date In SQL

Here we will explain how to find the Indian financial year and financial quarter in a particular date with an example in SQL Server.
 
In India the new financial year starts on April 1.
 
I have used the CASE statement and DATEPART() function to achieve this requirement.
 

DATEPART() in SQL Server

 
The DATEPART() function returns a specified part of a date, like – year, month, day, hour, minute, etc.
 

CASE Statement in SQL Server

 
CASE is the extension of IF ... ELSE statement. So, once a condition is true, it will stop reading & return the result. If no conditions are true, it returns the value in the ELSE block.
 
A) Find the FINANCIAL YEAR from date
 
Write the below-given SQL code to find the financial year from given particular date,
  1. DECLARE@FilterDateASDATETIME  
  2. SET@FilterDate = GETDATE()  
  3. SELECTCASEWHENDATEPART(QUARTER,@FilterDate)= 1 THENYEAR(@FilterDate)ELSEYEAR(@FilterDate)+ 1 ENDAS[FINANCIAL_YEAR]  
  4. ** Note - @FilterDate - The date to be find the financial year 
Output
 
Following is the result of the SQL query for financial year,
 
B) Find the FINANCIAL QUARTER from date
 
Write the below SQL code to find the financial Quarter from given particular date,
  1. DECLARE@FilterDateASDATETIME  
  2. SET@FilterDate = GETDATE()  
  3. SELECTCASEDATEPART(QUARTER, @FilterDate)WHEN 1 THEN'Q4'WHEN 2 THEN'Q1'WHEN 3 THEN'Q2'WHEN 4 THEN'Q3'ENDAS[FINANCIAL_QUARTER]  
  4. ** Note - @FilterDate - The date to be find the financial Quarter 
Output
 
Following is the result of the SQL query for the financial quarter,