Once the function has been created, the function can be called as follows:
SELECT dbo.fcn_FindEasterSunday(2008)
Once the function has been created, the function can be called as follows:
SELECT dbo.fcn_FindEasterSunday(2008)
SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS OFF GO CREATE FUNCTION dbo.fcn_FindEasterSunday(@inYear int) RETURNS datetime AS BEGIN DECLARE @dtNow datetime DECLARE @inCurDay int DECLARE @inCurMonth int DECLARE @inCurYear int DECLARE @inCurCent int DECLARE @inYear19 int DECLARE @inYearTmp int DECLARE @inTemp2 int DECLARE @inTemp3 int DECLARE @inTemp4 int DECLARE @inEastDay int DECLARE @inEastMonth int DECLARE @dtEasterSunday datetime SET @dtNow = CONVERT(datetime,CAST(@inYear as char(4))+'-01-01') SET @inCurDay=DAY(@dtNow) SET @inCurMonth=MONTH(@dtNow) SET @inCurYear=YEAR(@dtNow) SET @inCurCent=FLOOR(@inCurYear/100) SET @inYear19=@inCurYear%19 SET @inYearTmp=FLOOR((@inCurCent-17)/25) SET @inTemp2=(@inCurCent-FLOOR(@inCurCent/4)-FLOOR((@inCurCent-@inYearTmp)/3)+(19*@inYear19)+15)%30 SET @inTemp2=@inTemp2-FLOOR(@inTemp2/28)*(1 - FLOOR(@inTemp2/28)*FLOOR(29/(@inTemp2+1))*FLOOR((21-@inYear19)/11)) SET @inTemp3 = (@inCurYear+FLOOR(@inCurYear/4)+@inTemp2+2-@inCurCent+FLOOR(@inCurCent/4))%7 SET @inTemp4 = @inTemp2-@inTemp3 SET @inEastMonth = 3+FLOOR((@inTemp4+40)/44) SET @inEastDay = @inTemp4+28-31*FLOOR(@inEastMonth/4) SET @inEastMonth = @inEastMonth - 1 SET @dtEasterSunday = CONVERT(datetime,CAST(@inCurYear as varchar(4))+'-'+RIGHT(CAST('00' as varchar(2))+CAST(@inEastMonth+1 as varchar(2)),2)+'-'+RIGHT(CAST('00' as varchar(2))+CAST(@inEastDay as varchar(2)),2)+' 00:00:00') RETURN @dtEasterSunday END GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO