hitk Posted July 11, 2010 Share Posted July 11, 2010 My Issue is similar to http://www.phpfreaks.com/forums/index.php?topic=139559 I want to list Upcoming 12 Months from today's month. Ex. We are in July Month so list should be, July 2010 August 2010 September 2010 ... . . . June 2011 I am using smarty, so plz, let me know. Quote Link to comment https://forums.phpfreaks.com/topic/207408-list-upcoming-12-months-since-current-month/ Share on other sites More sharing options...
xcasio Posted July 11, 2010 Share Posted July 11, 2010 Would this work? for ($x = 0; $x < 12; $x++) { echo date('F Y', strtotime('+ '.$x.' month')).'<br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/207408-list-upcoming-12-months-since-current-month/#findComment-1084384 Share on other sites More sharing options...
PFMaBiSmAd Posted July 11, 2010 Share Posted July 11, 2010 ^^^ the posted code will experience problems on the last day(s) of the month because it uses the current date/time and it will skip and produce duplicates when the current day number does not exist in the months you are looping over. Using mktime() would be better because you can easily specify the first day of the month (or any day that exists in every month) and in fact since strtotime() uses mktime internally, mktime would be slightly faster. <?php $month = date('n'); // current month for ($x = 0; $x < 12; $x++) { echo date('F Y', mktime(0,0,0,$month + $x,1)) . '<br />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/207408-list-upcoming-12-months-since-current-month/#findComment-1084436 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.