easter_days


php apg

RETURNS the number of days after March 21 on which Easter falls for a given year.



<?php

int easter_days 
int|null $year null 
                                
int $mode CAL_EASTER_DEFAULT )


where,

$year The year as a integer or null

$mode 
To allow the Easter dates to be calculated based on the 
              Gregorian calendar during the years 1582 
1752 
                 
SEE the below TABLE )

?>

 $year 


The year as a integer.



 $mode 

CONSTANT VAL WHAT DOES DEFAULT
CAL_EASTER_DEFAULT 0 Calculate Easter for years before 1753 according to the Julian calendar, and for later years according to the Gregorian calendar CAL_EASTER_DEFAULT
CAL_EASTER_ROMAN 1 Calculate Easter for years before 1583 according to the Julian calendar, and for later years according to the Gregorian calendar
CAL_EASTER_ALWAYS_GREGORIAN 2 Calculate Easter according to the proleptic Gregorian calendar
CAL_EASTER_ALWAYS_JULIAN 3 Calculate Easter according to the Julian calendar
ed48




Sinze PHP 8.0.0 $year is nullable.

The entered $year is between 1970 and 2037.

If $year = null or omitted, the $year assumes the current year according to the localtime.

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.



  1 EXERCISE   

<?php

date_default_timezone_set
('America/Los_Angeles');

$days2yeareaster01 easter_days(date("Y"));

$dtdftz01 date_default_timezone_get();
setlocale(LC_ALL"en_US""american"
                                      
"american english",
                                      
"american-english"
                                      
"english-american"
                                      
"english-us"
                                      
"english-usa""enu"
                                      
"us""usa");

echo 
$days2yeareaster01 ' days after March 21.<br>
This means that 31 days are missing for Easter.<br><br>'
;

$d21mar01 strtotime('Mar 21 ' date("Y") . ' 00:00:00');

$tseaster01 strtotime('+'$days2yeareaster01 ' days'$d21mar01);

$deastr01 strftime("%A, %B %d, %Y %Hh %Mmin %Ss"$tseaster01); 

echo 
$deastr01 '.<br><br>';

?> 

  2 EXERCISE   

<?php

date_default_timezone_set
('America/Sao_Paulo');

$days2yeareaster02 easter_days(date("Y"));

$dtdftz02 date_default_timezone_get();
setlocale(LC_ALL"pt_BR.utf-8""portuguese-brazil""ptb");

echo 
$days2yeareaster02 ' days after March 21.<br>
This means that 31 days are missing for Easter.<br><br>'
;

$d21mar02 strtotime('Mar 21 ' date("Y") . ' 00:00:00');

$tseaster02 strtotime('+'$days2yeareaster02 ' days'$d21mar02);

$deastr02 strftime("%A, %B %d, %Y %Hh %Mmin %Ss"$tseaster02); 

echo 
$deastr02 '.<br><br>';

?>

  3 EXERCISE   

<?php

date_default_timezone_set
('UTC');

$days2yeareaster03 easter_days(date("Y"));

$dtdftz03 date_default_timezone_get();
setlocale(LC_ALL"en_US""american"
                                      
"american english"
                                      
"american-english"
                                      
"english-american"
                                      
"english-us"
                                      
"english-usa"
                                      
"enu""us""usa");

echo 
$days2yeareaster03 ' days after March 21.<br>
This means that 31 days are missing for Easter.<br><br>'
;

$d21mar03 strtotime('Mar 21 ' date("Y") . ' 00:00:00');

$tseaster03 strtotime('+'$days2yeareaster03 ' days'$d21mar03);

$deastr03 strftime("%A, %B %d, %Y %Hh %Mmin %Ss"$tseaster03); 

echo 
$deastr03 '.<br><br>';

?>

  4 EXERCISE   

<?php

date_default_timezone_set
('UTC');

$year04 mt_rand(15821752);

$days2yeareaster04 easter_days($year04CAL_EASTER_ROMAN);

$dtdftz04 date_default_timezone_get();
setlocale(LC_ALL"en_US""american"
                                   
"american english"
                                   
"american-english"
                                   
"english-american"
                                   
"english-us"
                                   
"english-usa"
                                   
"enu""us""usa");

echo 
$days2yeareaster04 ' days after March 21.<br>
This means that 31 days are missing for Easter.<br><br>'
;

$d21mar04 strtotime('Mar 21 ' $year04 ' 00:00:00');

$tseaster04 strtotime('+'$days2yeareaster04 ' days'$d21mar04);

$deastr04 strftime("%A, %B %d, %Y %Hh %Mmin %Ss"$tseaster04); 

echo 
$deastr04 '.<br><br>';

?>

  5 EXERCISE   

<?php

date_default_timezone_set
('America/Sao_Paulo');

$tmnow05 time();

$datenow05 date('Y-m-d'$tmnow05);

echo 
$datenow05 '<br><br>';

$alwgr05 mt_rand(19702037);

$year05 idate("Y");

$tmnew05 = (array)date_create($alwgr05 '-03-31');

$tm05 $tmnew05['date'];

$sub05 substr($tm05010);

echo 
$sub05 '<br>';


// CAL_EASTER_ALWAYS_GREGORIAN
$alwgr05n easter_days($alwgr05CAL_EASTER_ALWAYS_GREGORIAN);

if(
$year05 <= $sub05)
{
echo 
'For the year: ' $alwgr05 '-03-21 will be missing '
 
$alwgr05n ' day (s) for the Easter.<br><br>';
}
else
{
echo 
'For the year: ' $alwgr05 '-03-21 was missing '
 
$alwgr05n ' day (s) for the Easter.<br><br>';    
}


?> 

  6 EXERCISE   

<?php

$alwjl06 
2021;

// CAL_EASTER_ALWAYS_GREGORIAN
$alwjl06n easter_days($alwjl06CAL_EASTER_ALWAYS_GREGORIAN);


echo 
'For the ' $alwjl06 '-03-21, was missing '
 
$alwjl06n ' day (s) for the Easter.<br><br>';

?>