note 24253 deleted from function.mcal-day-of-week by danbrown

From: Date: Fri, 28 Nov 2008 21:47:04 +0000
Subject: note 24253 deleted from function.mcal-day-of-week by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147269@lists.php.net to get a copy of this message
Note Submitter: cigalcohol at yahoo dot com ---- 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"; ?>

« previous php.notes (#147269) next »