Link to home
Start Free TrialLog in
Avatar of evibesmusic
evibesmusicFlag for United States of America

asked on

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?
Avatar of Cornelia Yoder
Cornelia Yoder
Flag of United States of America image

$monthnamearray = array("January","February", ... ,"December");

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

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

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Andyc75
Andyc75
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of evibesmusic

ASKER

Like a glove my friend.  Perfect.  Thanks.
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.