Re: Saturdays and Sundays

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

« previous php.general (#221698) next »