List all Mondays
By: Daniel
Ever need some code to list all the Mondays in a specified year? Here is some code to do just that:
function getMondays($year) { $newyear = $year; $week = 0; $day = 0; $mo = 1; $mondays = array(); $i = 1; while ($week != 1) { $day++; $week = date("w", mktime(0, 0, 0, $mo,$day, $year)); } array_push($mondays,date("r", mktime(0, 0, 0, $mo,$day, $year))); while ($newyear == $year) { $test = strtotime(date("r", mktime(0, 0, 0, $mo,$day, $year)) . "+" . $i . " week"); $i++; if ($year == date("Y",$test)) { array_push($mondays,date("r", $test)); } $newyear = date("Y",$test); } return $mondays; } echo '<pre>'; print_r(getMondays('2006')); echo '</pre>';




















(1 votes, average: 4.00 out of 5)
October 17th, 2008 at 2:35 am
For some reason it skips the second monday of the year? I cant seem to find out why though.