If you want to make it a few line shorter, change
if ($MonthStartDay < $Day)
{
$C = $Day - $MonthStartDay;
}
else if ($MonthStartDay > $Day)
{
$C = 7 - $MonthStartDay + $Day;
}
to
$C = ($MonthStartDay > $Day ? 7 : 0) + $Day - $MonthStartDay;
or maybe
$C = ($MonthStartDay < $Day ? 0 : 7) + $Day - $MonthStartDay;
I haven't tried either one, so it may break it...
If one, or both, work, then you could combine this line with the "return"
line
-----Original Message-----
From: Ed Lazor [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 29, 2002 2:44 PM
To: Rasmus Lerdorf
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] easy date question?
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php