skip to Main Content

Windows 11 64 bit

This code only yields up to year 2037. I thought the year 2037 was limited only to 32 bit systems. XAMPP v3.30 stops on 2037 but same code online gives 1970 01 January for every year beyond 2037. Thanks.

$year=2025;

while ($year <= 2050) 
{
    $easterDate = easter_date($year);
    echo $easterYear = date('Y', $easterDate), " ";
    echo $easterDay = date('d', $easterDate), " ";
    echo $easterMonth = date('F', $easterDate), "<br>";

    $year++;
}

2

Answers


  1. I thought the year 2037 was limited only to 32 bit systems.

    No. The function itself can be limited to the years 1970 and 2037 (inclusive).

    And note that it has been removed in many PHP >= 5.4 configurations (ref: https://3v4l.org/Jfvi6).

    Login or Signup to reply.
  2. I would not rely on easter_date() as it has a lot of caveats. If you look at the notes in the documentation, it shows a better way that uses PHP’s built-in date function to calculate Easter for a given year and allows going beyond 2037 since it doesn’t rely on unix timestamps. The easter_days() function which returns the numbers of days Easter is from March 21:

    function get_easter_datetime($year) {
        $base = new DateTime("$year-03-21");
        $days = easter_days($year);
    
        return $base->add(new DateInterval("P{$days}D"));
    }
    
    foreach (range(2012, 2153) as $year) {
        printf("Easter in %d is on %sn",
               $year,
               get_easter_datetime($year)->format('F j'));
    }
    

    Outputs:

    Easter in 2012 is on April 8
    Easter in 2013 is on March 31
    Easter in 2014 is on April 20
    ...
    Easter in 2151 is on April 4
    Easter in 2152 is on April 23
    Easter in 2153 is on April 15
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search