note 63696 added to function.date
| From: | php-general at lists dot php dot net | Date: | Tue, 28 Mar 2006 15:44:42 +0000 |
| Subject: | note 63696 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-106853@lists.php.net to get a copy of this message | ||
Here is a function to calculate easter sunday for any year from 1900 to 4099, pass the year into the
function and it will return the date in the format dd/mm/yyyy
function calcEasterSunday($year){
$frac = $year/19;// GET THE FRACTION OF THE DATE
$fraction = explode(".",$frac);
//============ Set the year parameter ==============================//
if($year <= 2199){
$useYear = 2199;
}else if($year <= 2299){
$useYear = 2299;
}else if($year <= 2399){
$useYear = 2399;
}else if($year <= 2499){
$useYear = 2499;
}else if($year <= 2599){
$useYear = 2599;
}else if($year <= 2899){
$useYear = 2899;
}else if($year <= 3099){
$useYear = 3099;
}else if($year <= 3399){
$useYear = 3399;
}else if($year <= 3499){
$useYear = 3499;
}else if($year <= 3599){
$useYear = 3599;
}else if($year <= 3699){
$useYear = 3699;
}else if($year <= 3799){
$useYear = 3799;
}else if($year <= 4099){
$useYear = 4099;
}
//========== calculate easter sunday ==============================//
$useFrac = substr($fraction[1],0,3);
$pfm = $pfmDate[$useFrac][$useYear];
$num1 = $tableB[$pfm];
$num2 = $tableC[substr($year,0,2)];
$num3 = $tableD[substr($year,2,2)];
$total = $num1+$num2+$num3;
$adddays = $tableE[$total];
//========== Create date for easter sunday ======================//
$days = substr($pfm,1,2)+$adddays;
$mon = (substr($pfm,0,1)=="A")? 4 : 3;
if($mon==3 && $days > date("t",mktime(12,0,0,3,1,$year))){
$days = $days-date("t",mktime(12,0,0,3,1,$year));
$mon = 4;
}
$easterSunday = date("d/m/Y",mktime(12,0,0,$mon,$days,$year));
return $easterSunday;
}
For the tables that i used to create the arrays $pfmDate, $tableB-E follow the link
http://www.assa.org.au/edm.html#Calculator
hope this helps someone
----
Server IP: 85.116.0.130
Probable Submitter: 84.45.193.14
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/note/edit/63696
Del: integrated -- http://master.php.net/note/delete/63696/integrated
Del: useless -- http://master.php.net/note/delete/63696/useless
Del: bad code -- http://master.php.net/note/delete/63696/bad+code
Del: spam -- http://master.php.net/note/delete/63696/spam
Del: non-english -- http://master.php.net/note/delete/63696/non-english
Del: in docs -- http://master.php.net/note/delete/63696/in+docs
Del: other reasons-- http://master.php.net/note/delete/63696
Reject -- http://master.php.net/note/reject/63696
Search -- http://master.php.net/manage/user-notes.php