note 78366 deleted from function.date by derick

From: Date: Sun, 09 Dec 2007 13:39:01 +0000
Subject: note 78366 deleted from function.date by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133005@lists.php.net to get a copy of this message
Note Submitter: davedx at g removeme mail dot com ---- 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]; }

« previous php.notes (#133005) next »