Get date for Easter in PHP

All the good things about Easter aside, it’s one of those holidays that’s a
pain to get the date for. This is because the date of Easter is based on the
lunar cycle and Spring Equinox (March 21st). The date of Easter on a given
year could fall between March 22nd and April 25th. Fortunately PHP has us
covered with a pair of functions, one to get the number of days after March
21st until Easter Sunday and a second function that gives us the exact date.

If you simply want to know the number of days after March 21st, you can use
easter_days() which takes a single argument for the year you want to know
the number of days for:

$days = easter_days(1981

Personally, this function doesn’t have much value to me when the counterpart
of easter_date() exists. The date function takes the same argument but keep
in mind that it returns the Unix timestamp, so if you want the date you will
need to use the date() function as well:

$easter_ts   = easter_date(1981
$easter_date = date('Y-m-d', $easter_ts

Knowing the date of Easter is also good for being able to determine a few other
important days like Ash Wednesday, Palm Sunday and Good Friday.

Happy Easter y’all!

Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.


If you found this article helpful, please consider buying me a coffee.