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
| Function | Purpose |
|---|---|
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
| Mistake | Correct Approach |
|---|---|
| Ignoring this behavior: Return value is a day offset, not a UNIX timestamp | Return 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.