note 78366 added to function.date
| From: | davedx at gremovememail dot com | Date: | Mon, 08 Oct 2007 14:50:08 +0000 |
| Subject: | note 78366 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131234@lists.php.net to get a copy of this message | ||
I made a minor modification to wes.wysoft.com's "nth day of the month" function. I
was attempting to convert Windows registry TIME_ZONE_INFORMATION structs to PHP dates to do timezone
+ DST conversions, and the registry entries don't seem to be quite right - for GMT, the correct
end of DST is "the last Sunday in October", but the windows registry stores it as
"the 5th Sunday in October"... but in 2007 there are only 4 Sundays! To protect from
further craziness, I do this:
function weekDayOf($year,$month,$dayoftheweek,$occurance) {
/*
* 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;
}
$n = $occurance;
while($n > 0 && !isset($day_oc[$dayoftheweek][$n]))
$n--;
return $day_oc[$dayoftheweek][$n];
}
----
Server IP: 194.145.210.4
Probable Submitter: 80.6.91.225
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/78366
Del: integrated -- https://master.php.net/note/delete/78366/integrated
Del: useless -- https://master.php.net/note/delete/78366/useless
Del: bad code -- https://master.php.net/note/delete/78366/bad+code
Del: spam -- https://master.php.net/note/delete/78366/spam
Del: non-english -- https://master.php.net/note/delete/78366/non-english
Del: in docs -- https://master.php.net/note/delete/78366/in+docs
Del: other reasons-- https://master.php.net/note/delete/78366
Reject -- https://master.php.net/note/reject/78366
Search -- https://master.php.net/manage/user-notes.php