Re: Saturdays and Sundays

From: Date: Thu, 01 Sep 2005 16:43:15 +0000
Subject: Re: Saturdays and Sundays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-221699@lists.php.net to get a copy of this message
""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); } ?>

« previous php.general (#221699) next »