note 37996 added to function.date
| From: | vadim dot kudryavtsev at mcgill dot ca | Date: | Thu, 04 Dec 2003 04:23:50 +0000 |
| Subject: | note 37996 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-61374@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37996
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37996&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37996&report=yes
Search -- http://master.php.net/manage/user-notes.php