note 71650 modified in function.getdate by danbrown

From: Date: Sun, 20 Jul 2008 03:06:43 +0000
Subject: note 71650 modified in function.getdate by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142022@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] <?php 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]); } ?> --was-- 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]); } http://php.net/manual/en/function.getdate.php

« previous php.notes (#142022) next »