I came up with a solution that I'd like to share. Could someone confirm
whether it's the best approach?
Thanks,
-Ed
--------- source code ----------------
# ex.: GetDay ("Third", "Saturday", 5, 2002);
function GetDay($Week, $Day, $Month, $Year)
{
$MonthStartDay = date("w", mktime(0,0,0,$Month,1,$Year) ) + 1;
switch ($Week)
{
case "First" : $Week = 0; break;
case "Second" : $Week = 7; break;
case "Third" : $Week = 14; break;
case "Fourth" : $Week = 21; break;
}
switch ($Day)
{
case "Sunday" : $Day = 1; break;
case "Monday" : $Day = 2; break;
case "Tuesday" : $Day = 3; break;
case "Wednesday" : $Day = 4; break;
case "Thursday" : $Day = 5; break;
case "Friday" : $Day = 6; break;
case "Saturday" : $Day = 7; break;
}
$C = 0;
if ($MonthStartDay < $Day)
{
$C = $Day - $MonthStartDay;
}
else if ($MonthStartDay > $Day)
{
$C = 7 - $MonthStartDay + $Day;
}
return ($C + 1 + $Week);
}
--------------------------------
At 05:55 PM 5/28/2002 -0700, Rasmus Lerdorf wrote:
>See the PEAR Date/Calc class.
>
>On Tue, 28 May 2002, Ed Lazor wrote:
>
> > How can I find out the date of the 3rd Tuesday of any given month?
> >
> > Thanks,
> >
> > -Ed
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php