Calculating the date of easter sunday

We’ve previously looked at how to calculate recurring public holidays. However, calculating the date of easter sunday is not as simple as you might think, because it involves calculations of lunar phases. This short post contains a T-SQL translation of the popularly used Meeus-Jones-Butcher formula.

According to swedish standards (and holiday legislation), easter sunday occurs on the first sunday following the first full moon on or after march 21. For the record, there are different easters – this post is about the western (i.e. Gregorian) easter sunday.

As I don’t know the first thing about astronomy, moon phases or religious holidays, I’ll cut straight to the chase. The formula calculates the number of days from january 1 for a specific year, using a number of variables. I’ve translated this into a scalar function that accepts @year as input and outputs the date of easter sunday for that year:

CREATE FUNCTION dbo.fn_easterSunday(@year smallint)

--- Calculates the date of easter sunday for a given year, using
--- the Meeus-Jones-Butcher algorithm.
--- Source:


    --- Variables used:
    DECLARE @a tinyint, @b tinyint, @c tinyint,
            @d tinyint, @e tinyint, @f tinyint,
            @g tinyint, @h tinyint, @i tinyint,
            @k tinyint, @l tinyint, @m tinyint,
            @date date;

    --- Calculation steps:
    SELECT @[email protected]%19, @b=FLOOR(1.0*@year/100), @[email protected]%100;
    SELECT @d=FLOOR(1.0*@b/4), @[email protected]%4, @f=FLOOR(([email protected])/25);
    SELECT @g=FLOOR(([email protected]@f)/3);
    SELECT @h=(19*@[email protected]@[email protected]+15)%30, @i=FLOOR(1.0*@c/4), @[email protected]%4;
    SELECT @l=(32.0+2*@e+2*@[email protected]@k)%7;
    SELECT @m=FLOOR((1.0*@a+11*@h+22*@l)/451);
    SELECT @date=
        DATEADD(dd, (@[email protected]*@m+114)%31,
            DATEADD(mm, FLOOR((1.0*@[email protected]*@m+114)/31)-1,
                DATEADD(yy, @year-2000, {d '2000-01-01'})

    --- Return the output date:
    RETURN @date;


As far as I can establish, the formula seems to work in all fairly “contemporary” years, i.e. 1800s, 1900s and 2000s.

Check back next week, to see how you can use this formula as a building block to create a list of public holidays that you could use in, for instance, a date dimension.

3 thoughts on “Calculating the date of easter sunday

  1. Pingback: Building a calendar dimension with public holidays « Sunday morning T-SQL

  2. Pingback: The Value of Calendar Tables, Part 2: Simplify Queries – 36 Chambers – The Legendary Journeys: Execution to the max!

  3. Pingback: Calculate Easter Sunday Dynamically using SQL -

Let me hear your thoughts!

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.