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:

<?php
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>';
?>
 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...
del.icio.us:List all Mondays digg:List all Mondays spurl:List all Mondays wists:List all Mondays simpy:List all Mondays newsvine:List all Mondays blinklist:List all Mondays furl:List all Mondays reddit:List all Mondays fark:List all Mondays blogmarks:List all Mondays Y!:List all Mondays smarking:List all Mondays magnolia:List all Mondays segnalo:List all Mondays

Leave a Reply

eXTReMe Tracker
geovisitors