Re: Saturdays and Sundays

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

 



Is it possible to get the number of saturdays and sundays for a given month
/ year?

This seems to work...


<?php

$month = 9;
$year = 2005;
$day = 1;

$ts = mktime(0, 0, 0, $month, $day, $year);

$week_day = date("w", $ts); // 0 (for Sunday) through 6 (for Saturday)

if ( $week_day > 0 && $week_day < 6 ) {
    $day += 6 - $week_day; // $day = first saturday
}

$ts = mktime(0, 0, 0, $month, $day, $year);
$tmp_month = date("n", $ts); // 1 - 12

while ( $month == $tmp_month ) {
    $num_satsuns += 2;
    $day += 7;

    $ts = mktime(0, 0, 0, $month, $day, $year);
    $tmp_month = date("n", $ts); // 1 - 12
}

print("Number of Sat/Suns: $num_satsuns\n");

?>

--
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