So, here\'s a funny little programming challenge. I was writing a quick method to determine all the market holidays for a particular year, and then I started reading about E
The SQL Server function below is more general than the accepted answer
The accepted answer is only correct for the range (inclusive) : 1900-04-15 to 2099-04-12
It uses the algorithm provided by The United States Naval Observatory (USNO)
http://aa.usno.navy.mil/faq/docs/easter.php
CREATE FUNCTION dbo.GetEasterSunday (@Y INT)
RETURNS DATETIME
AS
BEGIN
-- Source of algorithm : http://aa.usno.navy.mil/faq/docs/easter.php
DECLARE @c INT = @Y / 100
DECLARE @n INT = @Y - 19 * (@Y / 19)
DECLARE @k INT = (@c - 17) / 25
DECLARE @i INT = @c - @c / 4 - (@c - @k) / 3 + 19 * @n + 15
SET @i = @i - 30 * (@i / 30)
SET @i = @i - (@i / 28) * (1 - (@i / 28) * (29 / (@i + 1)) * ((21 - @n) / 11))
DECLARE @j INT = @Y + @Y / 4 + @i + 2 - @c + @c / 4
SET @j = @j - 7 * (@j / 7)
DECLARE @l INT = @i - @j
DECLARE @m INT = 3 + (@l + 40) / 44
DECLARE @d INT = @l + 28 - 31 * (@m / 4)
RETURN
(
SELECT CONVERT
( DATETIME,
RTRIM(@Y)
+ RIGHT('0'+RTRIM(@m), 2)
+ RIGHT('0'+RTRIM(@d), 2)
)
)
END
GO