| 
	
 | 
 Posted by Janwillem Borleffs on 06/17/70 11:51 
Stuart Colman wrote: 
> I need to display every Monday and Thursday, and their relevant dates 
> for a given month. 
> 
> I have looked at a few things, but not really got past being able to 
> show one Monday or Thursday. 
> 
> Any ideas or pointers? 
> 
 
function getMonThuForMonth($month, $year = 0) { 
    // Day array 
    $dates = array(); 
 
    // set the year 
    if (!$year) $year = date('Y'); 
 
    // verify the month 
    if ($month < 1 || $month > 12) return false; 
 
    // first: get initial timestamp 
    $ts = mktime(0, 0, 0, $month, 1, $year); 
 
    // get all timestamps related to the Mondays 
    // and Thursdays of the month 
    while ($month == date('m', $ts)) { 
        if ('Mon' == date('D', $ts)) { 
            $dates[] = $ts; 
        } 
 
        $day = date('D', $ts = strtotime('thursday', $ts)); 
        if ($month == date('m', $ts)) { 
            $dates[] = $ts; 
        } 
 
        $ts = strtotime('next monday', $ts); 
    } 
    return $dates; 
} 
 
$dates = getMonThuForMonth(6); 
foreach ($dates as $date) { 
    echo date('Y M D (d)', $date), '<br />'; 
} 
 
 
JW
 
[Back to original message] 
 |