I need to output a list of dates (only Mondays and Tuesdays) for the next 12 months from current date like so:
Jan 2010
Tue 12 Jan 2010
Mon 18 Jan 2010<
Ok now that your computers date is Wednesday you want to print the Mondays before the Tuesdays as the next Monday is closer to Wednesday than the next Tuesday. So try this:
$blockedDatesInput = "08 Mar 2010,12 Apr 2010"; // dont show these dates
$blockedDates = explode ("," , $blockedDatesInput); // convert to array
$currentMonth = ""; // current month marker
// loop over the next 52 weeks to find Mondays and Tuesdays
for($i=0; $i<=52; $i++){
// build the month header
$monthReference = date("M Y", strtotime('+'.$i.' Week'));
// check if date exists in $blockeddate
if (!in_array(date("d M Y", strtotime('+'.$i.' Monday')), $blockedDates) ||
!in_array(date("d M Y", strtotime('+'.$i.' Tuesday')), $blockedDates) ) {
// check if we have to show a new month
if(strcmp($monthReference, $currentMonth) <> 0){
echo $monthReference.'
',"\n";
}else{
// output the dates (changed the order as suggested by Aly)
echo date("D d M Y", strtotime('+'.$i.' Monday')).'
',"\n";
echo date("D d M Y", strtotime('+'.$i.' Tuesday')).'
',"\n";
}
$currentMonth = date("M Y", strtotime('+'.$i.' Week'));
}
}