create function [dbo].[CalculateEaster](@year int) returns date as /*--- Begin Testing ---*/ /* declare @year int = 2020 -- easter = 4/12/2020 */ /*--- End Testing ---*/ begin declare @century int = @year / 100 ,@remainder19 int = @year % 19 declare @centuryAdj int = (@century - 17) / 25 declare @yearAdj1 int = @century - (@century / 4) - ((@century - @centuryAdj) / 3) + (19 * @remainder19) + 15 set @yearAdj1 = @yearAdj1 % 30 set @yearAdj1 = @yearAdj1 - (@yearAdj1 / 28) * (1 - (@yearAdj1 / 28) * (29 / (@yearAdj1 + 1)) * ((21 - @remainder19) / 11)) declare @yearAdj2 int = @year + @year / 4 + @yearAdj1 + 2 - @century + @century / 4 set @yearAdj2 = @yearAdj2 % 7 declare @yearAdjNet int = @yearAdj1 - @yearAdj2 declare @month int = 3 + (@yearAdjNet + 40) / 44 declare @day int = @yearAdjNet + 28 - (31 * (@month / 4)) declare @result date = datefromparts(@year, @month, @day) return @result --select result = @result end
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.