|
Posted by Philip Hallstrom on 10/19/81 11:26
> 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");
?>
Navigation:
[Reply to this message]
|