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? Link to comment https://forums.phpfreaks.com/topic/92443-php-month-name/ 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 />"; } Link to comment https://forums.phpfreaks.com/topic/92443-php-month-name/#findComment-473609 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 />'; } ?> Link to comment https://forums.phpfreaks.com/topic/92443-php-month-name/#findComment-473629 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. Link to comment https://forums.phpfreaks.com/topic/92443-php-month-name/#findComment-473683 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 />'; } ?> Link to comment https://forums.phpfreaks.com/topic/92443-php-month-name/#findComment-473700 Share on other sites More sharing options...
p2grace Posted February 22, 2008 Share Posted February 22, 2008 Yeup that one would work. Link to comment https://forums.phpfreaks.com/topic/92443-php-month-name/#findComment-473706 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.