DaveLinger Posted July 10, 2007 Share Posted July 10, 2007 I'm designing a website for a car club, and on their info page it says that they meet on every first and third Thursdays of each month except December. I think it would be a cool added trick to just have a line under that that would say "The next meeting is on July 5", or whatever. How could I accomplish this? Quote Link to comment Share on other sites More sharing options...
Caesar Posted July 10, 2007 Share Posted July 10, 2007 The very easiest approach would be to create a table for "events" (Or something). And simple add these to the table and store the event date as a timestamp (use columns like event id, event description, event information, event date...etc blah blah) and grab them for display purposes. You can then easily check with is the next even. That would be the easiest. :-) Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 10, 2007 Share Posted July 10, 2007 You can get away with using the strtotime() and date() functions: <?php $timestamp = strtotime('next thursday'); $date = date('F d',$timestamp); echo 'The next meeting is on '.$date; //produces The next meeting is on July 12 ?> You'll need to add in something to miss out any dates in december though. EDIT: Whoops - i just realised i really didn't think this through, it wont work properly. Tis too late for me Quote Link to comment Share on other sites More sharing options...
Carterhost Posted July 10, 2007 Share Posted July 10, 2007 Example from php.net which could be useful: <?php $lastthurs=strtotime("last Thursday",mktime(0,0,0,date("n")+1,1)); ?> Returns the last thursday of this month. <?php $firstthurs=strtotime("next Thursday",mktime(0,0,0,date("n"),1)); ?> Returns the first thursday of this month. So if I didn't need more coffee to stay awake, I'd work out the code for you. 1. Test whether you're past the first thursday of the month 2. If yes, get the date of the last thursday. If no, get the date of the first. 3. Convert it to a nice format 4. Echo it Quote Link to comment Share on other sites More sharing options...
DaveLinger Posted July 10, 2007 Author Share Posted July 10, 2007 So can I say... if(date() > $firstthurs){echo $lastthurs}else{echo $firstthurs} ? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 11, 2007 Share Posted July 11, 2007 This was annoying me so i decided to sort it out. Firstly though, there is actualy a problem with the code for the first thursday. If the first thursday happened to be the first day of the month, currently we would get the 2nd thursday, as the function passes in the first day of the current month and then asks for NEXT thursday. So, in the mktime function, we actually need to pass in last month, and the last day of the last month: $firstthurs=strtotime("next thursday",mktime(0,0,0,date("n")-1,date('t',mktime(0,0,0,date('n')-1)))); Anyways, heres what i came up with. Im pretty sure it works: <?php $curr_month = date('m'); $curr_day = date('d'); $firstthurs=strtotime("next thursday",mktime(0,0,0,date("n")-1,date('t',mktime(0,0,0,date('n')-1)))); $thirdthurs_day_no=date('d',$firstthurs+60*60*24*14);//need third thursday rather than last, so add two weeks $firstthurs_day_no = date('d',$firstthurs);//get day number if($curr_month >= 11 && $curr_day > $thirdthurs_day_no){//check to see if we are past the last meeting of the year - the 3rd thursday of november $next_meeting = strtotime('next thursday',mktime(0,0,0,12,31,date('Y'))); $next_meeting = date('d F Y',$next_meeting); }else{ if($curr_day < $firstthurs_day_no){//before first thursday of the month $next_meeting = date('d F Y',$firstthurs); }elseif($curr_day < $thirdthurs_day_no){//between 1st and 3rd thursday $next_meeting = date('d F Y',$firstthurs+60*60*24*14); }else{//after 3rd thursday of current month, so next meeting is 1st thursday of next month $next_meeting =strtotime("next Thursday",mktime(0,0,0,date("n"),date('t'))); $next_meeting =date('d F Y',$next_meeting); } } echo 'The next meeting is on '.$next_meeting; //produces The next meeting is on 19 July 2007 ?> 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.