guttyguppy Posted July 21, 2007 Share Posted July 21, 2007 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! Quote Link to comment Share on other sites More sharing options...
metrostars Posted July 21, 2007 Share Posted July 21, 2007 How long do courses last? Are all weeks the same format or are they alternating? Do you want dates etc stored in a dtabase or would you like them to be starting date & formst to be entered each time? Quote Link to comment Share on other sites More sharing options...
guttyguppy Posted July 23, 2007 Author Share Posted July 23, 2007 Courses are 16 weeks. Weeks are same format. Starting date and sequence change each semester. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 23, 2007 Share Posted July 23, 2007 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. Quote Link to comment Share on other sites More sharing options...
guttyguppy Posted July 24, 2007 Author Share Posted July 24, 2007 Thank you so much! I will try it and report back. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.