Content · Programming · PHP

PHP easter_days() Function: Usage and Examples

Learn how PHP easter_days works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Calculates the number of days after March 21 on which Easter Sunday falls.

What Is easter_days() in PHP?

Calculates the number of days after March 21 on which Easter Sunday falls.

Its syntax is:

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

Parameters:

  • $year — Accepted as ?int; optional default null.
  • $mode — Accepted as int; optional default CAL_EASTER_DEFAULT.

Return type: int. Return value is a day offset, not a UNIX timestamp. Calendar mode and supported year range matter.

Availability: Requires the calendar extension.

Example 1: Basic Usage

<?php

echo easter_days(2025);

Output:

30

Return value is a day offset, not a UNIX timestamp. Calendar mode and supported year range matter.

Example 2: A Different Input

<?php

echo easter_days(2026);

Output:

15

Return value is a day offset, not a UNIX timestamp. Calendar mode and supported year range matter.

Practical Example: Applying It in a Program

<?php

$years = [2024, 2025, 2026]; foreach ($years as $year) { echo $year . ": " . easter_days($year) . PHP_EOL; }

Output:

2024: 10
2025: 30
2026: 15

Return value is a day offset, not a UNIX timestamp. Calendar mode and supported year range matter.

Important Behavior and Edge Cases

  • Key behavior: Return value is a day offset, not a UNIX timestamp. Calendar mode and supported year range matter.
  • Environment: Requires the calendar extension.

Comparison With Related Functions

FunctionPurpose
easter_days()Calculates the number of days after March 21 on which Easter Sunday falls.
easter_date()easter_date() produces a Unix timestamp for Easter on supported systems; easter_days() returns an offset from March 21.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: Return value is a day offset, not a UNIX timestampReturn value is a day offset, not a UNIX timestamp. Calendar mode and supported year range matter.

Key Takeaways

  • Calculates the number of days after March 21 on which Easter Sunday falls.
  • Return value is a day offset, not a UNIX timestamp. Calendar mode and supported year range matter.
  • Requires the calendar extension.

Summary: Return value is a day offset, not a UNIX timestamp. Calendar mode and supported year range matter.

Share this resourceSend this page to someone who may find it useful.