phaedo5 Posted February 22, 2008 Share Posted February 22, 2008 I'd like to make a simple list of month names - January through December where the starting month is the current month: February March April... I was going to go simple adding 1 to date('F'), but that doesn't work. What would be the best way of doing this? Quote Link to comment Share on other sites More sharing options...
p2grace Posted February 22, 2008 Share Posted February 22, 2008 This should do the trick: echo date("F",strtotime("Jan"))."<br />"; for($i=1;$i<=11;$i++){ echo date('F',strtotime("Jan +$i month"))."<br />"; } Quote Link to comment Share on other sites More sharing options...
obsidian Posted February 22, 2008 Share Posted February 22, 2008 IMHO, here's a cleaner way: <?php // Start with current month $curr_month = date('m'); for ($i = 0; $i < 12; $i++) { echo date('F', mktime(0,0,0,$curr_month + $i)) . '<br />'; } ?> **EDIT** BTW, if you did want to use strtotime() for this, here's an easy way to modify the above: <?php for ($i = 0; $i < 12; $i++) { echo date('F', strtotime("+{$i} month")) . '<br />'; } ?> Quote Link to comment Share on other sites More sharing options...
p2grace Posted February 22, 2008 Share Posted February 22, 2008 It was my understanding that he didn't want to start with the current month, he wants to start with the first month. Jan-Dec. Quote Link to comment Share on other sites More sharing options...
obsidian Posted February 22, 2008 Share Posted February 22, 2008 It was my understanding that he didn't want to start with the current month, he wants to start with the first month. Jan-Dec. Here's a refresher of the OP (note the part in bold): I'd like to make a simple list of month names - January through December where the starting month is the current month Either way, even starting with January, you could consolidate slightly like this: <?php for ($i = 0; $i < 12; $i++) { echo date('F', strtotime("January 1 +{$i} month")) . '<br />'; } ?> Quote Link to comment Share on other sites More sharing options...
p2grace Posted February 22, 2008 Share Posted February 22, 2008 Yeup that one would work. 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.