Re: 4 or 5 Fridays this month
| From: | Rob Adams | Date: | Wed, 02 Apr 2003 07:22:59 +0000 |
| Subject: | Re: 4 or 5 Fridays this month | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-141938@lists.php.net to get a copy of this message | ||
>"Liam Gibbs" <liamgibbs@sympatico.ca> wrote in message
news:003501c2f8df$a5d17bc0$4d59fea9@TeletranOne...
>Is there any easy way of figuring out if there are 4 or if there are 5
Fridays in a given month? I have it >figured out using a loop, but I was
just wondering if there was a way that date() or strtotime() could >do it.
K - given a month and year of $month, $year: (not really much prettier
than a loop...)
function num_fridays($month, $year)
{
$fdom = mktime(0, 0, 0, $month, 1, $year);
$wday = date("w", $fdom); // get weekday
if ($wday > 5 or $wday < 3) // 5 Fridays impossible.
return 4;
$lday = date("t", $fdom); // get number of days in the month
$buffer = $lday - 28;
if ($wday >= (5 - $buffer) and ($wday <= 5))
return 5;
else
return 4;
}
This worked for me on a couple test months.
-- Rob