Jump to content

showing only Monday-Thursday in this simple calendar


sw45acp

Recommended Posts

I wrote this very simple calendar to write out the dates of a given month and year.  It adds a line break at the end of each week. What I want, however, is for it to only output days that are Monday-Thursday, not Sunday,Friday, or Saturday. I would appreciate help on this matter.

 

//january 2010
$m = 1;
$y = 2010;
//calculate the number of days in the month
$days = date('t',mktime(0,0,0,$m, 1, $y));
//Calculate the day of the week that the month starts on
$startDay = date('w',mktime(0,0,0,$m, 1, $y));
for ($i=1; $i<=$days; $i++) {
//output the days with a space
echo $i . ' ';
//increment the startday
$startDay ++;
//if the start day equals seven, which is not possible because
//sunday = 0, saturday =6, so we need to start a new line
if ($startDay == 7) {
	echo '<br />';
	//set start day back to zero
	$startDay = 0;
}
}

//january 2010
$m = 1;
$y = 2010;
//calculate the number of days in the month
$days = date('t',mktime(0,0,0,$m, 1, $y));
//Calculate the day of the week that the month starts on
$startDay = date('w',mktime(0,0,0,$m, 1, $y));
for ($i=1; $i<=$days; $i++) {
//output the days with a space
                if($startday+1<5 && $startday>0)
          echo $i . ' ';
                else
                          echo '  ';//if not in mon to thurs, echo 2 spaces
//increment the startday
$startDay ++;
//if the start day equals seven, which is not possible because
//sunday = 0, saturday =6, so we need to start a new line
if ($startDay == 7) {
	echo '<br />';
	//set start day back to zero
	$startDay = 0;
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.