# Calculating Easter: The longest scientific Project ever?

On Friday, I’d managed to work myself into a rage about something. I then sat down and wrote the following function in TSQL that tells you the date of Easter for any year you wish. Afterwards, I felt sublimely at peace with the world. Perhaps I remain an unreconstructed geek, after all.

This is one bit of code that that I shall not attempt to document. I’ll explain why afterwards.

ALTER FUNCTION Easter ( @input_date DATETIME )
/*
calculates the date of easter for the given year. This calculation
is the current one approved by the vatican. It differs from
the greek orthodox.

e.g.
DECLARE @Easter TABLE
(
year INT,
Easter DATETIME
)
DECLARE @TheYear DATETIME
SELECT  @TheYear = DATEADD(year, -15, CURRENT_TIMESTAMP)
WHILE DATEDIFF(year, @TheYear, ‘1 Jun 2020’) > 0
BEGIN
INSERT  INTO @Easter ( Year, Easter )
SELECT  DATEPART(year, @TheYear),
dbo.easter(@TheYear)
SELECT  @TheYear = DATEADD(year, 1, @TheYear)
END
SELECT  year,
CONVERT(CHAR(11), Easter, 113) AS [Easter Day]
FROM    @easter
*/
RETURNS DATETIME
WITH EXECUTE AS CALLER
AS BEGIN
DECLARE @y INTEGER,
@dy INTEGER,
@easter VARCHAR(20),
@easter_month INTEGER,
@easter_day INTEGER ;

SET @y = DATEPART(YEAR, @input_date) ;

SET @dy = ( ( 19 * ( @y % 19 ) + ( @y / 100 ) – ( ( @y / 100 ) / 4 ) – ( ( ( @y / 100 ) – ( ( ( @y / 100 ) + 8 ) / 25 ) + 1 ) / 3 ) + 15 ) % 30 ) + ( ( 32 + 2 * ( ( @y / 100 ) % 4 ) + 2 * ( ( @y % 100 ) / 4 ) – ( ( 19 * ( @y % 19 ) + ( @y / 100 ) – ( ( @y / 100 ) / 4 ) – ( ( ( @y / 100 ) – ( ( ( @y / 100 ) + 8 ) / 25 ) + 1 ) / 3 ) + 15 ) % 30 ) – ( ( @y % 100 ) % 4 ) ) % 7 ) – 7 * ( ( ( @y % 19 ) + 11 * ( ( 19 * ( @y % 19 ) + ( @y / 100 ) – ( ( @y / 100 ) / 4 ) – ( ( ( @y / 100 ) – ( ( ( @y / 100 ) + 8 ) / 25 ) + 1 ) / 3 ) + 15 ) % 30 ) + 22 * ( ( 32 + 2 * ( ( @y / 100 ) % 4 ) + 2 * ( ( @y % 100 ) / 4 ) – ( ( 19 * ( @y % 19 ) + ( @y / 100 ) – ( ( @y / 100 ) / 4 ) – ( ( ( @y / 100 ) – ( ( ( @y / 100 ) + 8 ) / 25 ) + 1 ) / 3 ) + 15 ) % 30 ) – ( ( @y % 100 ) % 4 ) ) % 7 ) ) / 451 ) + 114 ;

SET @easter_month = @dy / 31 ;
SET @easter_day = ( @dy % 31 ) + 1 ;

— assumes proprietary, non-ANSI local temporal format
SET @easter = CASE @easter_month
WHEN 3 THEN ‘Mar’
ELSE ‘Apr’
END ;
SET @easter = @easter + SPACE(1) + CAST(@easter_day AS VARCHAR(2)) + ‘, ‘
+ CAST(@y AS VARCHAR(4))
RETURN CAST(@easter AS DATETIME) ;

END ;

The story of the date of Easter is tinged with farce. By the third century, Christians had settled down to the idea of celebrating the anniversary of Jesus’ resurrection. Unfortunately, nobody at the time had thought of jotting down the date when it happened. They felt sure that it had happened some time in the Jewish month of Nisan, at around the full moon. The Jewish calendar was lunar, and Christians were forced to rely on the Jews to tell them when the month  approached. Even then, calculating the Sunday after the full moon was almost impossible then, so the date chosen varied between Christian communities. At the council of Nicaea, in 325 AD,  Constantine determined that all Christians should celebrate on the same day, and they decided that Easter should be on the first Sunday after the first full moon after the spring equinox, but not if it occurred on the same day as the Jewish Passover. Constantine wasn’t a ‘small detail’ man and optimistically concluded “we ought not to have anything with the (Jewish calendar), for the Saviour has shown us another way”. He hadn’t. They should have chosen a fixed date.

At this stage, I can imagine the astronomers, the geeks of the day, weeping, for much the same reasons as we weep now when managers promise the unattainable from IT. Even the fixed date would have been a compromise:  Caesar’s calendar was flawed, any fixed date for the vernal equinox drifted by 11 minutes a year. Calculating the date of the full moon required a precise calculation of the sun, orbit of the earth and phases of the moon. and had to take into account the drift of the calendar.  It also had to compensate for the elliptical orbits of the planets, and the various gravitational effects. They couldn’t do the calculation accurately then, and the struggle over the centuries to get the right answer  funded the dim flickering light of science, even at the darkest of times. In the nineteenth century, a millennium and a half later, Vatican scholars finally produced a complex fourteen-part algorithm to calculate the date, and it is still in use today. I nominate this as the longest, and most expensive, IT project ever.

The formula used gets the right date, but it is difficult to comprehend, and seems flawed to me. Nevertheless, it is the way Easter is calculated, so there is no sense in correcting it, unless you wish to start a new Christian sect. Meanwhile, the Greek Orthodox church have a different set of calculations for calculating Easter, but that is another story