PHP easter_days() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Calendar

Definition

In PHP, easter_days() returns the number of days between March 21 and Easter Sunday for a given year.

Easter always falls on or after March 22, so the answer is a small number from 1 to 35. You can add it to March 21 to build the Easter date yourself. Unlike easter_date(), it does not depend on Unix timestamps, so it works for a much wider range of years.

Syntax

Call easter_days() with the values you need. Start with this line.

PHP
$days = easter_days(2024);
CallWhat it does
easter_days(2024)Returns 10, so Easter 2024 is 10 days after March 21 (March 31).
easter_days(2025)Returns 30, so Easter 2025 is April 20.
easter_days(2024, CAL_EASTER_ALWAYS_JULIAN)Returns 32 using the Julian calendar rules, which gives the Orthodox style date.

The number counts days from March 21 of the calendar being used. Add it with DateTime::modify() or mktime() to get the full date. If you leave out the year, PHP uses the current year.

Library declarations
PHP
easter_days(?int $year = null, int $mode = CAL_EASTER_DEFAULT): int

Parameters

ParameterDescription
yearOptional. The year to calculate for. If it is null or omitted, the current year is used.
modeOptional. The rule used: CAL_EASTER_DEFAULT (0), CAL_EASTER_ROMAN (1), CAL_EASTER_ALWAYS_GREGORIAN (2) or CAL_EASTER_ALWAYS_JULIAN (3). The default uses Julian rules for years up to 1752 and Gregorian rules after that.

Return Value

Return ValueDescription
intThe number of days after March 21 on which Easter Sunday falls.

PHP Examples

Example 1 — Days After March 21

Check a few fixed years to see how early or late Easter can be.

PHP
<?php
echo easter_days(2024), PHP_EOL;
echo easter_days(2025), PHP_EOL;
echo easter_days(2000), PHP_EOL;
echo easter_days(2008), PHP_EOL;

How It Works

  1. easter_days(2024) is 10, so Easter is March 31.
  2. easter_days(2025) is 30, so Easter is April 20 (10 more days of March plus 20 of April).
  3. easter_days(2000) is 33, which is April 23.
  4. easter_days(2008) is only 2, which is March 23, one of the earliest dates in recent years.

Example 2 — Calendar Modes and Old Years

The mode argument changes the rules. Year 1700 comes before the default switch to Gregorian, so the two modes disagree.

PHP
<?php
echo easter_days(1700), PHP_EOL;
echo easter_days(1700, CAL_EASTER_ALWAYS_GREGORIAN), PHP_EOL;
echo easter_days(2024, CAL_EASTER_ALWAYS_JULIAN), PHP_EOL;
echo easter_days(1900), PHP_EOL;

How It Works

  1. For 1700 the default mode uses the Julian rules, which gives 10.
  2. CAL_EASTER_ALWAYS_GREGORIAN forces the Gregorian rules and gives 21.
  3. CAL_EASTER_ALWAYS_JULIAN for 2024 gives 32, counted from March 21 in the Julian calendar.
  4. Unlike easter_date(), easter_days() has no 1970 limit, so 1900 works and returns 25.

Example 3 — Build the Easter Date

Add the number of days to March 21 using DateTime to get the real date.

PHP
<?php
$year = 2024;
$days = easter_days($year);

$date = new DateTime($year . '-03-21');
$date->modify('+' . $days . ' days');

echo 'Days after March 21: ', $days, PHP_EOL;
echo 'Easter Sunday: ', $date->format('Y-m-d'), PHP_EOL;
echo 'Weekday: ', $date->format('l'), PHP_EOL;

How It Works

  1. easter_days() returns 10 for the year 2024.
  2. A DateTime object is created for March 21 of the same year.
  3. modify('+10 days') moves the date forward to March 31.
  4. Formatting with l prints the weekday name, and Easter is always a Sunday.

Frequently Asked Questions

It tells you how many days after March 21 Easter Sunday falls in a given year. Add that number to March 21 to get the date.
Church rules say Easter is the first Sunday after the first full moon on or after March 21. March 21 is the fixed starting point for the calculation, so PHP returns the distance from it.
Use easter_days() when you want to avoid Unix timestamps, time zones, or years outside the 1970 range. Use easter_date() when you simply want a timestamp for Easter Sunday.
The value goes from 1 (March 22) to 35 (April 25). Easter can never be earlier than March 22 or later than April 25 in the Gregorian calendar.
Yes. easter_days() is part of the calendar extension. Enable extension=calendar in php.ini or install the php-calendar package if the function is undefined.

Next: frenchtojd()

frenchtojd() converts a French Republican date into a Julian Day number.

frenchtojd() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful