Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Calendar Functions : easter_date

easter_date

Get Unix timestamp for midnight on Easter of a given year (PHP 4, PHP 5)
int easter_date ( [int year] )

Returns the Unix timestamp corresponding to midnight on Easter of the given year.

Warning:

This function will generate a warning if the year is outside of the range for Unix timestamps (i.e. before 1970 or after 2037).

The date of Easter Day was defined by the Council of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. The Equinox is assumed to always fall on 21st March, so the calculation reduces to determining the date of the full moon and the date of the following Sunday. The algorithm used here was introduced around the year 532 by Dionysius Exiguus. Under the Julian Calendar (for years before 1753) a simple 19-year cycle is used to track the phases of the Moon. Under the Gregorian Calendar (for years after 1753 - devised by Clavius and Lilius, and introduced by Pope Gregory XIII in October 1582, and into Britain and its then colonies in September 1752) two correction factors are added to make the cycle more accurate.

(The code is based on a C program by Simon Kershaw, <webmaster at ely.anglican dot org>)

Parameters

year

The year as a number between 1970 an 2037

Return Values

The easter date as a unix timestamp.

ChangeLog

Version Description
Since 4.3.0 The year parameter is optional and defaults to the current year according to the local time if omitted.

Examples

Example 367. easter_date() example

<?php

echo date("M-d-Y", easter_date(1999));        // Apr-04-1999
echo date("M-d-Y", easter_date(2000));        // Apr-23-2000
echo date("M-d-Y", easter_date(2001));        // Apr-15-2001

?>


See Also
easter_days() for calculating Easter before 1970 or after 2037
See Also
easter_days()

Code Examples / Notes » easter_date

ray

The algorithm from BigTree will throw an error in 2021 and 2025.  Better to install the PHP functions!  Details here:
http://aa.usno.navy.mil/faq/docs/easter.html


phpuser

The algorithm from Bigtree is correct if you add some (int) cast
<?php
  function easter_date ($Year) {
 
      /*
      G is the Golden Number-1
      H is 23-Epact (modulo 30)
      I is the number of days from 21 March to the Paschal full moon
      J is the weekday for the Paschal full moon (0=Sunday,
        1=Monday, etc.)
      L is the number of days from 21 March to the Sunday on or before
        the Paschal full moon (a number between -6 and 28)
      */
     
        $G = $Year % 19;
        $C = (int)($Year / 100);
        $H = (int)($C - (int)($C / 4) - (int)((8*$C+13) / 25) + 19*$G + 15) % 30;
        $I = (int)$H - (int)($H / 28)*(1 - (int)($H / 28)*(int)(29 / ($H + 1))*((int)(21 - $G) / 11));
        $J = ($Year + (int)($Year/4) + $I + 2 - $C + (int)($C/4)) % 7;
        $L = $I - $J;
        $m = 3 + (int)(($L + 40) / 44);
        $d = $L + 28 - 31 * ((int)($m / 4));
        $y = $Year;
        $E = mktime(0,0,0, $m, $d, $y);
        return $E;
  }
?>


14-aug-2006 03:46

I made the function like this ... works fine !
function ostern
{
   $maerz21=date('z',mktime(0,0,0,3,21,$jb));
   $d=((15 + $jb/100 - $jb/400 - (8 * $jb/100 + 13) / 25)%30 + 19 * ($jb%19))%30;
   if ($d==29)
   {
       $D=28;
   }
   elseif($d==28 && ($jb%17)>=11)
   {
       $D=27;
   }
   else $D=$d;    
   $e=(2 * ($jb%4) + 4 *($jb%7) + 6 * $D + (6 + $jb/100 - $jb/400 - 2)%7)%7;
   $ostersonntag=$e+$D+1+$maerz21;
   return $ostersonntag;
}


bigtree

A much smaller hack is the following. I ported this from a Delphi implementation of a function calculating easter dates.
<?php
   function easter_date ($Year) {
   
       /*
       G is the Golden Number-1
       H is 23-Epact (modulo 30)
       I is the number of days from 21 March to the Paschal full moon
       J is the weekday for the Paschal full moon (0=Sunday,
         1=Monday, etc.)
       L is the number of days from 21 March to the Sunday on or before
         the Paschal full moon (a number between -6 and 28)
       */
       
         $G = $Year % 19;
         $C = (int)($Year / 100);
         $H = (int)($C - ($C / 4) - ((8*$C+13) / 25) + 19*$G + 15) % 30;
         $I = (int)$H - (int)($H / 28)*(1 - (int)($H / 28)*(int)(29 / ($H + 1))*((int)(21 - $G) / 11));
         $J = ($Year + (int)($Year/4) + $I + 2 - $C + (int)($C/4)) % 7;
         $L = $I - $J;
         $m = 3 + (int)(($L + 40) / 44);
         $d = $L + 28 - 31 * ((int)($m / 4));
         $y = $Year;
         $E = mktime(0,0,0, $m, $d, $y);
         return $E;
   }
?>


Change Language


Follow Navioo On Twitter
cal_days_in_month
cal_from_jd
cal_info
cal_to_jd
easter_date
easter_days
FrenchToJD
GregorianToJD
JDDayOfWeek
JDMonthName
JDToFrench
JDToGregorian
jdtojewish
JDToJulian
jdtounix
JewishToJD
JulianToJD
unixtojd
eXTReMe Tracker