Created
August 4, 2009 17:17
-
-
Save jasonjohnson/161356 to your computer and use it in GitHub Desktop.
day_of_week
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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