note 24253 added to function.mcal-day-of-week
| From: | cigalcohol@php.net | Date: | Sat, 10 Aug 2002 18:35:23 +0000 |
| Subject: | note 24253 added to function.mcal-day-of-week | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-34783@lists.php.net to get a copy of this message | ||
I don't have the MCAL lib, so I wrote a script that will return the day of the week for any
date 2000+ using Zeller's Rule:
http://mathforum.org/dr.math/faq/faq.calendar.html
I only needed it to work for this century, so I replaced a few variables with constants, and I split
up the equation itself into its component parts because I'm something of a n00b and I get
condused easily.
$y needs to be two digits, not four, eg, "02", "13", vs 2002, 2013, &c.
<?
if ( $m >= "3") {
$mn = $m - 2; }
else {
$mn = $m + 10; }
if ( $mn >= "11" ) {
$yn = $y - 1; }
else { $yn = $y; }
$rem = $d;
$rem = floor((13*$mn-1)/5) + $rem;
$rem = $rem + $yn;
$rem = floor($yn/4) + $rem;
$rem = $rem - 35;
$rem = $rem % 7;
if ($rem < 0) {
$rem = $rem + 7;}
if ($rem == "0") { $w = "Sun"; }
elseif ($rem == "1") { $w = "Mon"; }
elseif ($rem == "2") { $w = "Tue"; }
elseif ($rem == "3") { $w = "Wed"; }
elseif ($rem == "4") { $w = "Thu"; }
elseif ($rem == "5") { $w = "Fri"; }
elseif ($rem == "6") { $w = "Sat"; }
echo "$m.$d.$y is a $w";
?>
--
http://www.php.net/manual/en/function.mcal-day-of-week.php
http://master.php.net/manage/user-notes.php?action=edit+24253
http://master.php.net/manage/user-notes.php?action=delete+24253
http://master.php.net/manage/user-notes.php?action=reject+24253