X

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.

Categories: PHP Programming
Tags: Algorithms
giampy107:
X

Cookies Policy

We use cookies to personalize content and ads, provide social media features and analyze our traffic. We also share information about your use of our site with our web analytics, advertising and social media partners who may combine it with other information you have provided to them or that they have collected based on your use of theirs. services.

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings