December 16, 2011

Get financial year from Todays date



DECLARE @StartDate DATETIME
DECLARE @TodaysDate DATETIME

SELECT @TodaysDate = CONVERT(DATETIME, CONVERT(CHAR(10),  Getdate(), 101), 101)

--If it is April 1 or greater, then the StartDate is the current year
IF MONTH(@TodaysDate) >= 4  SELECT @StartDate = CONVERT(CHAR(4), YEAR(@TodaysDate)) + '0401'
--Otherwise, it's the previous year
ELSE SELECT @StartDate = CONVERT(CHAR(4), YEAR(@TodaysDate)-1) + '0401'

SELECT @StartDate AS StartDate, @TodaysDate AS EndDate

No comments:

Post a Comment