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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.