note 37996 deleted from function.date by tomsommer
| From: | tomsommer@php.net | Date: | Sat, 17 Jul 2004 13:21:50 +0000 |
| Subject: | note 37996 deleted from function.date by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73444@lists.php.net to get a copy of this message | ||
Note Submitter: vadim.kudryavtsev@mcgill.ca
----
hey here
i was looking for a function that returns number of weeks for a given year and month. well, i could
not find it so here is my solution.
function m_weeks($y, $m){
// monthday array
$monthdays = array(1=>31, 3=>31, 4=>30, 5=>31, 6=>30,7=>31,
8=>31, 9=>30, 10=>31, 11=>30, 12=>31);
// weekdays remaining in a week starting on 7 - Sunday...(could be changed)
$weekdays = array(7=>7, 1=>6, 2=>5, 3=>4, 4=>3, 5=>2, 6=>1);
$date = mktime( 0, 0, 0, $m, 1, $y);
$leap = date("L", $date);
// if it is a leap year set February to 29 days, otherwise 28
$monthdays[2] = ($leap ? 29 : 28);
// get the weekday of the first day of the month
$wn = strftime("%u",$date);
$days = $monthdays[$m] - $weekdays[$wn];
return (ceil($days/7) + 1);
}
hope it'll help.
vadim