Jump to content

PHP Month Name


phaedo5

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.