W3docs

easter_date()

Learn how to calculate the date of Easter Sunday in PHP using the easter_date() and easter_days() functions, with timezone-safe examples.

Introduction

Calculating the date of Easter programmatically is a surprisingly common task — calendar apps, scheduling systems, and payroll software all need to know which day of the year Easter falls on, because the date moves every year. PHP ships two built-in functions for this, easter_date() and easter_days(). This chapter explains how Easter is computed, how each function behaves, and which one to reach for to avoid timezone surprises.

Why the date of Easter moves

Easter is a movable feast: unlike Christmas, it has no fixed calendar date. By the rule set at the Council of Nicaea in 325 AD, Easter Sunday is the first Sunday after the first full moon on or after the vernal (spring) equinox. Because that depends on the lunar cycle, the date drifts between March 22 and April 25 from year to year.

PHP implements the standard computus algorithm internally, so you never have to compute the lunar phase yourself.

easter_date()

easter_date() returns the Unix timestamp for Easter Sunday of a given year.

  • Signature: easter_date(?int $year = null, int $mode = CAL_EASTER_DEFAULT): int
  • Parameters: The four-digit $year (defaults to the current year). The optional $mode selects the Gregorian or Julian calculation.
  • Return value: A Unix timestamp for Easter Sunday.

Note: A common mistake is to pass a timestamp to easter_date(). The argument is a year (e.g. 2023), not a timestamp. Passing mktime(...) produces a wrong result.

The catch is timezones. The returned timestamp points at noon UTC of Easter Sunday, so formatting it with date() under a default timezone west of UTC can roll the result back to the previous day. For display, prefer the easter_days() approach below.

easter_days()

easter_days() returns the number of days after March 21 on which Easter falls, instead of a timestamp. This is the timezone-safe building block: combine it with a plain calendar date and you get the correct day regardless of date_default_timezone_set().

  • Signature: easter_days(?int $year = null, int $mode = CAL_EASTER_DEFAULT): int
  • Return value: An integer offset (for example, 19 means March 21 + 19 days).

Availability: easter_date() and easter_days() are part of PHP's calendar extension. They were moved into core in PHP 8.0 and are still available in current PHP (8.x) — they were not removed. If you see Call to undefined function easter_date() on an older build, enable the calendar extension.

Example code

Recommended — timezone-safe via easter_days()

<?php

$year = 2023;
$easter = (new DateTimeImmutable("$year-03-21"))
    ->modify('+' . easter_days($year) . ' days');

echo $easter->format('F j, Y'); // Outputs: April 9, 2023

Quick one-liner with easter_date()

<?php

$year = 2023;
echo date('F j, Y', easter_date($year));

easter_date() anchors the timestamp to noon UTC, so the calendar day you see depends on the formatting timezone — note how the same year prints differently below. This is exactly why the easter_days() version above is the safer choice:

<?php

date_default_timezone_set('UTC');
echo date('F j, Y H:i', easter_date(2024)); // Outputs: March 30, 2024 20:00

Conclusion

Easter is a movable feast, so its date must be computed from the lunar calendar each year. PHP does the hard math for you through the calendar extension. For display code, prefer easter_days() combined with a DateTimeImmutable so the result is unaffected by the server's timezone; use easter_date() for a quick timestamp when you control the default timezone.

Practice

Practice
What does the easter_date() function in PHP return?
What does the easter_date() function in PHP return?
Was this page helpful?