Skip to content

Instantly share code, notes, and snippets.

@jasonjohnson
Created August 4, 2009 17:17
Show Gist options
  • Save jasonjohnson/161356 to your computer and use it in GitHub Desktop.
Save jasonjohnson/161356 to your computer and use it in GitHub Desktop.
day_of_week
<?php
function day_of_week($day, $month, $year = null, $limit = 20) {
$found_day = false;
$days = array();
$time = mktime(0, 0, 1, $month, 1, ($year?$year:date('Y')));
if(date('Y', $time) == $day)
$found_day = true;
// Search for our first $day
while(!$found_day) {
$time += 86400;
if(date('D', $time) == $day)
$found_day = true;
}
// Remember our first 'day'
$days[] = $time;
// Jump ahead 7 days $limit times
for($i = 0; $i < $limit; $i++) {
$time += 604800;
$days[] = $time;
}
return $days;
}
$tuesdays = day_of_week('Tue', 10, 2009);
foreach($tuesdays as $tuesday) {
print(date('D M j G:i:s T Y', $tuesday)."\n");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment