Home Â» PLSQL Â» Determining the Dates of Easter for Any Year in Oracle PLSQL

# Determining the Dates of Easter for Any Year in Oracle PLSQL

## Determining the Dates of Easter for Any YearÂ  in Oracle PLSQL

Problem
You would like to dynamically determine the dates of Easter for a given year.
Solution
Oracle doesnâ€™t provide a single, elegant function to perform Easter calculations for you. But Oracle does
have robust date arithmetic functions that we can use to build our own Easter calculator. This begs the
question, how do we decide the dates of Easter anyway?
For Easter under the Gregorian calendar, Easter Sunday is the Sunday following the first full moon
after Lent. Contemporary algorithms translate this to the first Sunday after the first full moon on or after
March 21.
The next function returns the date of Easter Sunday for a specified year.
create or replace function easter_sunday(given_year number) return date
as
golden_metonic number;
century number;
leap_year_fix number;
lunar_sync number;
sunday_date number;
epact number;
day_of_month number;
easter_offset number;
begin
golden_metonic := mod(given_year,19) + 1;
century := (given_year / 100) + 1;
leap_year_fix := (3 * century / 4) - 12;
lunar_sync := ((8 * century + 5)/25) - 5;
sunday_date := (5 * given_year / 4) - leap_year_fix - 3;
epact := mod((11 * golden_metonic + 20 + lunar_sync - leap_year_fix),30);
if((epact = 25 and golden_metonic < 11) or (epact = 24)) then
epact := epact + 1;
end if;
day_of_month := 44 - epact;
if(day_of_month < 21) then
day_of_month := day_of_month + 30;
end if;
easter_offset := (day_of_month + 7 - mod((sunday_date + day_of_month),7)) - 1;
end;
/
We could have coded this in pure SQL as one rather large nested set of IF and CASE statements, but
this function is both easier to read and easier to use in practice. We can now find Easter for any given
year, such as 2000 shown in the next SQL statement.
select easter_sunday(2000)
from dual;
EASTER_SUNDAY
-------------
23-APR-00
We can also dynamically determine Easter Sunday for the current year without needing to explicitly
state the year. The next SQL statement illustrates this in action.
select easter_sunday(extract(year from (sysdate)))
from dual;
EASTER_SUNDAY
-------------

12-APR-09