tao83 Posted September 12, 2009 Share Posted September 12, 2009 I've got a page where it lists events and the dates of the events: September 2009 Name of event 1-2 September 2009 Name of event 3-4 September 2009 October 2009 Name of event 1-2 October 2009 3-4 October 2009 I've used "mktime" PHP function in a "while" loop to move the month up by 1 as it lists the events in each upcoming month. However, I've hit a problem where it just stops listing the events in November 2009. I can't seem to figure out how to increment the month into the next year as well (ie. display December 2009 events and then January 2010 events). <?php $today = time();//get today's date $today = date('Y-m-d', $today);//formate today's date $day = date('d', strtotime($today));//capture day into separate variable $month = date('m', strtotime($today));//capture month into separate variable $year = date('Y', strtotime($today));//capture year into separate variable $end_of_month = mktime(0, 0, 0, $month+1, 0, $year); //set end of active month $end_of_month = date('Y-m-d', $end_of_month);//format end of month date while (condition) { echo "$month $year"; while ($dates=mysql_fetch_array($var)) { ...... echo "event dates"; } $today = mktime(0, 0, 0, $month+1, 1, date('Y')); $today = date('Y-m-d', $today); //Once all scheduled dates finished, go onto next month $day = date('d', strtotime($today)); $month = date('m', strtotime($today)); $year = date('Y', strtotime($today)); $end_of_month = mktime(0, 0, 0, $month+1, 0, $year); //reset end of active month $end_of_month = date('Y-m-d', $end_of_month); } //end of first loop Basically if anyone can help me correctly increment from December 2009 to January 2010 that would be great! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/173978-list-of-scheduled-events-with-mktime-problem/ Share on other sites More sharing options...
RussellReal Posted September 12, 2009 Share Posted September 12, 2009 mktime() usually will if you put 13 months it will increase the year for you and put you on January >.> says so in the manual last time I checked. Quote Link to comment https://forums.phpfreaks.com/topic/173978-list-of-scheduled-events-with-mktime-problem/#findComment-917312 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.