Jump to content

[SOLVED] Date script for semester long classes


guttyguppy

Recommended Posts

Hi all, I'm trying to write a basic script that will fill in dates for me automatically. Specifically, I teach classes on either Monday/Wednesday/Friday, or Tuesday/Thursday sequences. I want to enter a starting date, say Monday, August 27th, 2007, and a course sequence, either MWF or TR, and have all dates for days accessible, so for instance for Tuesday on the 14th week of class, I can just put Tuesday, <?php echo classDate[14] ?> and have it echo the date of that class.

Thanks for any advice!

You can accomplish a lot with the strtotime() function. Got bored,so put this together for you:

 

<?php
function getdates($sequence,$startdate){
	$previous_day = strtotime($startdate) - 60*60*24;//get day before start date - will remove any issues with start day being a day of the class
if($sequence == 'MWF'){
	for($x=0;$x<16;$x++){
	 	$next_monday = strtotime('next monday',$previous_day);
	 	$next_monday = date('l d F Y',$next_monday);
	 	echo "You have a class on $next_monday <br />";
	 	$next_weds = strtotime('next wednesday',$previous_day);
	 	$next_weds = date('l d F Y',$next_weds);
	 	echo "You have a class on $next_weds <br />";
	 	$next_fri = strtotime('next friday',$previous_day);
	 	$next_fri = date('l d F Y',$next_fri);
	 	echo "You have a class on $next_fri <br />";
	 	$previous_day = $previous_day+60*60*24*7;//add a week onto this date
	}
}else{//sequence is tuesday/thursday
	for($x=0;$x<16;$x++){
	 	$next_tues = strtotime('next tuesday',$previous_day);
	 	$next_tues = date('l d F Y',$next_tues);
	 	echo "You have a class on $next_tues <br />";
	 	$next_thurs = strtotime('next thursday',$previous_day);
	 	$next_thurs = date('l d F Y',$next_thurs);
	 	echo "You have a class on $next_thurs <br />";	
	 	$previous_day = $previous_day+60*60*24*7;//add a week onto this date
	}
}
}
getdates('MWF','07/30/2007');//note the american start date format
echo '<hr />';
getdates('TR','07/30/2007');
?>

 

Of course, you might not wish to echo the dates, but that should get you started.

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.