Return to Snippet

Revision: 22280
at January 7, 2010 14:52 by aristoworks


Initial Code
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) {
	    $x =  strtotime(date("r", mktime(0, 0, 0, $mo,$day, $year)) . "+" . $i . " week");
	    $i++;
	    if ($year == date("Y",$x)) {
	      array_push($mondays,date("r", $x));
	    }
	    $newyear = date("Y",$x);
	  }
	  return $mondays;
	}

Initial URL
http://www.aristoworks.com

Initial Description
This is a simple function that will return an array of all the dates corresponding to the day 'Monday' for a given year.  It's pretty simple and may not be the cleanest way but it works for my purpose.

Initial Title
Retrieve All of the 'Monday's for a given year.

Initial Tags
php, date, function

Initial Language
PHP