Re: Saturdays and Sundays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sorry, I made a mistake. See below:
""Brian P. O'Donnell"" <brian@xxxxxxxxxxx> wrote in message
news:5B.F7.15098.8CF27134@xxxxxxxxxxxxxxx
>
> ""Shaun"" <shaunthornburgh@xxxxxxxxxxx> wrote in message
> news:05.80.15098.C4FC6134@xxxxxxxxxxxxxxx
> > 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

The following line referenced a variable in the other function. DUH!
It should be:
   $last_day = mktime(12, 0, 0, $month, date("t", mktime(12, 0, 0, $month,
1, $year)), $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);
>
> }
>
> ?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux