PHP Code to Find the Date of Easter

Here’s the source code to implement a php page to calculate the day of the Christian Easter.

function CalcEaster($aa, $mm, $gg)
{
   $gm = Array(22, 22, 23, 23, 24, 24);
   $da = Array(2, 2, 3, 4, 5, 5);
   $a = $aa % 19;
   $b = $aa % 4;
   $c = $aa % 7;
   $i = floor($aa / 100) - 15;
   $d = (19 * $a + $gm[$i]) % 30;
   $e = (2 * $b + 4 * $c + 6 * $d + $da[$i]) % 7;
   $gg = 22 + $d + $e;
   $mm = 3;
   if ($gg > 31)
   {
     $mm = 4;
     $gg -= 31;
   }
}

$easter = "";
$year = $_REQUEST['year'];
if (strlen($year) <= 0)
{
   $year = "";
}
else
{
   if (is_numeric($year))
   {
      $dp = "";
      $mp = "";

      CalcEaster($year, $mp, $dp);

      $easter = $dp;
      $easter .= " ";

      switch ($mp)
     {
       case 1:
          $easter .= "January ";
          break;
       case 2:
          $easter .= "February ";
          break;
       case 3:
         $easter .= "March ";
         break;
       case 4:
        $easter .= "April ";
        break;
       case 5:
        $easter .= "May ";
        break;
       case 6:
        $easter .= "June ";
        break;
       case 7:
        $easter .= "July ";
        break;
       case 8:
        $easter .= "August ";
        break;
       case 9:
        $easter .= "September ";
        break;
       case 10:
        $easter .= "October ";
        break;
       case 11:
         $easter .= "November ";
        break;
       case 12:
        $easter .= "December ";
        break;
    }

    $easter .= $year;
  }
}

I remember the day of the Christian Easter is the first Sunday after the first full moon after the spring equinox.

This entry was posted in PHP, Programming and tagged . Bookmark the permalink.