note 84199 modified in function.date by danbrown

From: Date: Sun, 20 Jul 2008 02:41:04 +0000
Subject: note 84199 modified in function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141975@lists.php.net to get a copy of this message
Slight amendment to halocastle at yahoo dot com 's code as it doesn't take into account when a month finishes on a Saturday (eg May 2008). <?php $start_date = mktime(0, 0, 0,$start_month, 1, $start_year); $days_in_month = date('t', $start_date); $month_first_day = date('w', $start_date); $j = $month_first_day; $num_weeks = 1; for($i = 1; $i <= $days_in_month; $i++) { $j++; if($j == 7) { $j = 0; $num_weeks++; } } // if the last day of the month happens to be a Saturday, // take one off the number of weeks // because it was being added inside the for loop. if ($j == 0) { $num_weeks--; } ?> --was-- Slight amendment to halocastle at yahoo dot com 's code as it doesn't take into account when a month finishes on a Saturday (eg May 2008). $start_date = mktime(0, 0, 0,$start_month, 1, $start_year); $days_in_month = date('t', $start_date); $month_first_day = date('w', $start_date); $j = $month_first_day; $num_weeks = 1; for($i = 1; $i <= $days_in_month; $i++) { $j++; if($j == 7) { $j = 0; $num_weeks++; } } // if the last day of the month happens to be a Saturday, // take one off the number of weeks // because it was being added inside the for loop. if ($j == 0) { $num_weeks--; } http://php.net/manual/en/function.date.php

« previous php.notes (#141975) next »