SDU Tools: Date of Orthodox Easter in SQL Server T-SQL

Some time back, we added DateOfEasterSunday to our free SDU Tools for developers and DBAs. Given it was the Christian Easter Sunday, almost immediately, I got a request for the Greek Orthodox Easter. That date isn’t of course just the Greek one, so we’ve added a new function DateOfOrthodoxEaster.
It’s based on a concept from Antonios Chatzipavlis. Thanks !
It takes a single parameter:
@Year int - the year to find the date for
And the return value is a date.
Find out more
You can see it in action in the main image above, and in the video here. The full current version of the code is also shown below:
You can use our tools as a set or as a great example of how to write functions like these.
Access to SDU Tools is one of the benefits of being an SDU Insider, along with access to our other free tools and eBooks. Please just visit here for more info:
http://sdutools.sqldownunder.com
Latest version of the code
Note: the code might wrap when displayed below.
CREATE OR ALTER FUNCTION SDU_Tools.DateOfOrthodoxEaster
(
@Year int
)
RETURNS date
AS
BEGIN
-- Function: Returns the date of Orthodox Easter in a given year
-- Parameters: @Year int -> year number
-- Action: Calculates the date of Orthodox Easter for
-- a given year, adapted from a code example
-- courtesy of Antonios Chatzipavlis
-- Return: date
-- Refer to this video: https://youtu.be/QbYx4k0ey8k
--
-- Test examples:
/*
SELECT SDU_Tools.DateOfOrthodoxEaster(2020);
SELECT SDU_Tools.DateOfOrthodoxEaster(1958);
*/
RETURN DATEADD(DAY, 13, CAST(CAST(@Year AS varchar(4))
+ RIGHT('0' + CAST(((((19 * (@Year % 19) + 15) % 30)
+ ((2 * (@Year % 4) + 4 * (@Year % 7)
- ((19 * (@Year % 19) + 15) % 30) +34) % 7)
+ 114) / 31) AS varchar(2)), 2)
+ RIGHT('0' + CAST((((((19 * (@Year % 19) + 15) % 30)
+ ((2 * (@Year % 4) + 4 * (@Year % 7)
- ((19 * (@Year % 19) + 15) % 30) +34) % 7)
+ 114) % 31) + 1) AS varchar(2)), 2) AS date));
END;
GO
2021-02-12