Article

Get Current Financial Year and Financial Year Dates Using SQL Server

10 Jun 2015 Kamal Pratap
0 Comments 1483 Views



Here we explain how to get dynamically current financial year first date and last date using SQL Server.

Get Current Financial Year and Financial Year Dates Using SQL Server

SQL Server :

DECLARE @MyDate1 DATETIME
SET @MyDate1 = GETDATE()
DECLARE @StartDate1 DATETIME
DECLARE @EndDate1 DATETIME

SET @StartDate1 = DATEADD(dd,0, DATEDIFF(dd,0, DATEADD( mm, -(((12 + DATEPART(m, GETDATE())) - 4)%12), GETDATE()) - datePart(d,DATEADD( mm, -(((12 + DATEPART(m, GETDATE())) - 4)%12),GETDATE()))+1 ) )
SET @EndDate1 = DATEADD(ss,-1,DATEADD(mm,12,@StartDate1 ))

Select @StartDate1 as FirstDay,@EndDate1 as LastDay

DECLARE @FIYear VARCHAR(20)    
    
SELECT @FIYear = (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 @FIYear AS F_YEAR   

 

Kamal Pratap

I have 6+ years experience in .Net technologies like Asp.Net, C#, WCF, Web Services, SQL Server, Ajax, LinQ. Currently I am working in Netcarrots Loyalty Services as a Software Developer.

Comments

No coments found to display!

Leave a Comment