PHP Month Number to Month Name
By gilbitron in PHP on 31/03/2009 at 03:17
Starter:
An easy way to convert a month number to a month name without a switch statement.
Main Course:
$monthName = date("F", mktime(0, 0, 0, $monthNum, 10));
Expand Report Code | Install Coda Clip
Please log in to vote.








Comment by http://www.myopenad.com on 30/05/2009 at 03:07
http://www.myopenad.com
Comment by Christopher Shennan on 27/07/2009 at 07:41
Fantastic... This was a nice quick solution to my problem. I was after the month names from November to Aprils so I tweaked this as follows:
for($i=1;$i
Comment by Christopher Shennan on 27/07/2009 at 07:42
Fantastic... This was a nice quick solution to my problem. I was after the month names from November to Aprils so I tweaked this as follows:
for($i=1;$i<=6;$i++) {
echo date("F", mktime(0, 0, 0, (($i+10) % 12), 10));
}
Comment by emeacham on 28/05/2010 at 07:07
mktime parameter count is off a bit for correct date creation.
PHP manual says:
int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] )
Anyone trying to copy and paste the exact code above, add a day (0, ) after $monthNum in mktime.
Comment by emeacham on 28/05/2010 at 07:21
errr... I fell into the same trap of not testing code before posting, too... :P
the 0 should be a 1... and I would stick with 1, and not try to be funny and go with the last day of the month, since every month has a first day (hence the 1) and not every day has 29 through 31.
Cheers :)
Comment by Chad G on 20/06/2010 at 08:54
Great tip, needed this for my site.