You are here: Re: Saturdays and Sundays « PHP « IT news, forums, messages
Re: Saturdays and Sundays

Posted by "Brian P. O'Donnell" on 10/20/95 11:26

""Shaun"" <shaunthornburgh@hotmail.com> wrote in message
news:05.80.15098.C4FC6134@pb1.pair.com...
> Hi,
>
> Is it possible to get the number of saturdays and sundays for a given
month
> / year?
>
> Thanks for your help.

Here's another way to do it. Each function will return either 4 or 5. If you
need both Saturdays and Sundays, just call both functions:

<?

function get_saturdays($month, $year) {

$sat = 4;

// time stamp of noon on the first day of the month
$first_day = mktime(12, 0, 0, $month, 1, $year);

switch ($month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if (date("w", $first_day) > 3) {
$sat++;
}
break;
case 2:
if ((date("L", $first_day) == 1) && (date("w", $first_day) > 5)) {
$sat++;
}
break;
case 4:
case 6:
case 9:
case 11:
if (date("w", $first_day) > 4) {
$sat++;
}
break;
}

return($sat);

}

function get_sundays($month, $year) {

$sun = 4;

// time stamp of noon on the last day of the month
$last_day = mktime(12, 0, 0, $month, date("t", $first_day), $year);

switch ($month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if (date("w", $last_day) < 3) {
$sat++;
}
break;
case 2:
if ((date("L", $last_day) == 1) && (date("w", $last_day) < 1)) {
$sat++;
}
break;
case 4:
case 6:
case 9:
case 11:
if (date("w", $last_day) < 2) {
$sat++;
}
break;
}

return($sun);

}

?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация