note 71650 added to function.getdate

From: Date: Sun, 10 Dec 2006 06:05:00 +0000
Subject: note 71650 added to function.getdate
Groups: php.notes 
Request: Send a blank email to php-notes+get-120467@lists.php.net to get a copy of this message
A nice little function I wrote to determine what number occurrence weekday it is of the month for a given timestamp. (I.e. 2nd Friday, or the 3rd Thursday) Eg: print_r(getWeekdayOccurrence(mktime(0, 0, 0, 12, 1, 2006))); Outputs: Array ( [0] => 1 [1] => Friday ) [The first friday] Eg. print_r(getWeekdayOccurrence(mktime(0, 0, 0, 8, 17, 2009))); Outputs: Array ( [0] => 3 [1] => Monday ) [The third Monday] function getWeekdayOccurrence($time) { $month = intval(date("m", $time)); $day = intval(date("d", $time)); for ($i = 0; $i < 7; $i++) { $days[] = date("l", mktime(0, 0, 0, $month, ($i+1), date("Y", $time))); } $posd = array_search(date("l", $time), $days); $posdm = array_search($days[0], $days) - $posd; / return array((($day+$posdm+6)/7), $days[$posd]); } ---- Server IP: 203.202.10.60 Probable Submitter: 121.73.28.111 (proxied: 121.73.28.111) ---- Manual Page -- http://www.php.net/manual/en/function.getdate.php Edit -- https://master.php.net/note/edit/71650 Del: integrated -- https://master.php.net/note/delete/71650/integrated Del: useless -- https://master.php.net/note/delete/71650/useless Del: bad code -- https://master.php.net/note/delete/71650/bad+code Del: spam -- https://master.php.net/note/delete/71650/spam Del: non-english -- https://master.php.net/note/delete/71650/non-english Del: in docs -- https://master.php.net/note/delete/71650/in+docs Del: other reasons-- https://master.php.net/note/delete/71650 Reject -- https://master.php.net/note/reject/71650 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120467) next »