[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 632
  • Last Modified:

Convert month number to month name

How can I convert month number into month date?

$Month = $getinfo2['Month'];

$Month is stored as 1-12, so that in the db January =1, February=2, etc.

How can I get the value of $Month not as a number but, as a name?
0
evibesmusic
Asked:
evibesmusic
1 Solution
 
Cornelia YoderArtistCommented:
$monthnamearray = array("January","February", ... ,"December");

$monthname = $monthnamearray[$monthnumber-1];

The minus 1 is because arrays are 0-indexed.
0
 
asafadisCommented:
A cleaner way of doing it:

$monthNumber = 8;
$monthName   = date("F", mktime(0, 0, 0, $monthNumber, 1, 2010));

Open in new window

0
 
Andyc75Commented:
You can take advantage of php's date function for this.

Just build your month value into a string and extract the full month name.

no need to manage an array of month names.


$date = strtotime('2010/' . $Month . '/01');

$month_name = date("F",$date);

echo $month_name;

Open in new window

0
 
evibesmusicAuthor Commented:
Like a glove my friend.  Perfect.  Thanks.
0
 
Cornelia YoderArtistCommented:
LOL@asafadis, if you think that is "cleaner" than what I posted.

@andyc75, that does exactly the same thing as mine, but mine does not rely on any external functions.

evibesmusic has chosen the solution s/he like the best, but I think dissing other Expert's ideas is really out of line for both of you.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now