note 24458 added to function.date
| From: | Paddy_Long at hotmail dot com | Date: | Fri, 16 Aug 2002 17:59:14 +0000 |
| Subject: | note 24458 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35140@lists.php.net to get a copy of this message | ||
/* this function is used to find the day of the week using the Doomsday Algorithm created by John
Horton Conway
for an explanation of the Doomsday Algorithm go to http://www.interlog.com/~r937/doomsday.html
parameters passed to it are $y = year, $m = month, $d = day of month (all numerical)
it results a numerical weekday where Sunday is 0 or -1 if an invalid month is given to it (something
out of the range of 1-12)
note that the function does work with leap years*/
function findweekday ($y, $m, $d){
$century = substr($y, 0, 2)."00";
if (($century-100) % 400 == "0"){
$cday = "0"; //Sunday
}elseif ($century % 400 == "0"){
$cday = "2"; //Tuesday
}elseif (($century+100) % 400 == "0"){
$cday = "3"; //Wednesday
}elseif (($century-200) % 400 == "0"){
$cday = "5"; //Friday
}
$y2 = substr($y, 2, 2);
$a = floor($y2 / 12);
$b = $y2 % 12;
$c = floor($b / 4);
$doomsday = $a + $b + $c + $cday;
$doomsday = $doomsday % 7;
if ($m == "1"){
if($y % 4 == 0 && $y % 100 != 0 || $y % 400 == 0){
$mdd = "-3";
}else{
$mdd = "-4";
}
}elseif ($m == "2"){
if($y % 4 == 0 && $y % 100 != 0 || $y % 400 == 0){
$mdd = "-6";
}else{
$mdd = "-7";
}
}elseif ($m == "3"){
$mdd = "-7";
}elseif ($m == "4"){
$mdd = "-3";
}elseif ($m == "5"){
$mdd = "-5";
}elseif ($m == "6"){
$mdd = "-1";
}elseif ($m == "7"){
$mdd = "-3";
}elseif ($m == "8"){
$mdd = "-6";
}elseif ($m == "9"){
$mdd = "-2";
}elseif ($m == "10"){
$mdd = "-4";
}elseif ($m == "11"){
$mdd = "-7";
}elseif ($m == "12"){
$mdd = "-2";
}else{
return -1;
}
$dif = $d - $mdd;
$weekday = ($doomsday + $dif) % 7;
return $weekday;
}
--
http://www.php.net/manual/en/function.date.php
http://master.php.net/manage/user-notes.php?action=edit+24458
http://master.php.net/manage/user-notes.php?action=delete+24458
http://master.php.net/manage/user-notes.php?action=reject+24458