note 77188 added to function.date
| From: | wes dot wysoft dot com at osu1 dot php dot net | Date: | Sun, 19 Aug 2007 03:58:27 +0000 |
| Subject: | note 77188 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129585@lists.php.net to get a copy of this message | ||
Well I looked all over the place for this and couldn't find it so I made my own. Hopefully it
saves someone else some time. It will give you the occurances of a day in a month. For example if
you want to get the date of the 2 Tuesday in a month.
<?php
function weekDayOf($year,$month,$dayoftheweek=null,$occurance=null) {
/*
* returns the # occurance of the day of the week. Such as the 3rd sunday
* if occurance is null it will return the whole array. for the week days in that month
* it can be accessed by $date[$dayoftheweek][$occurance]=date;
*/
$mdays=date("t",mktime(0,0,0,$month,1,$year)); //days in the current month
$first_day = date('w',mktime(0,0,0,$month,1,$year)); // day of the week the month started
with
$day_oc = array(); // occurances of each day of the week
for($i=0;$i<$mdays;++$i){
$dayofweek = ($i+$first_day)%7;
if(!is_array($day_oc[$dayofweek])) {
$day_oc[$dayofweek] = array();
}
$day_oc[$dayofweek][]=$i+1;
}
return $dayoftheweek ? $day_oc[$dayofweek][$occurance] : $day_oc;
}
?>
----
Server IP: 208.69.120.35
Probable Submitter: 67.169.253.227
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/77188
Del: integrated -- https://master.php.net/note/delete/77188/integrated
Del: useless -- https://master.php.net/note/delete/77188/useless
Del: bad code -- https://master.php.net/note/delete/77188/bad+code
Del: spam -- https://master.php.net/note/delete/77188/spam
Del: non-english -- https://master.php.net/note/delete/77188/non-english
Del: in docs -- https://master.php.net/note/delete/77188/in+docs
Del: other reasons-- https://master.php.net/note/delete/77188
Reject -- https://master.php.net/note/reject/77188
Search -- https://master.php.net/manage/user-notes.php