Get month name
This function changes a numerical month (e.g. 3) into the name of that month (e.g. March).
function getmonth($m=0) {
return (($m==0 ) ? date(”F”) : date(”F”, mktime(0,0,0,$m)));
}
?>
Use this textbox to search for articles on PHPit. Seperate keywords with a space.
This function changes a numerical month (e.g. 3) into the name of that month (e.g. March).
function getmonth($m=0) {
return (($m==0 ) ? date(”F”) : date(”F”, mktime(0,0,0,$m)));
}
?>
January 6th, 2006 at 4:24 pm
A shorter way (which returns the current month if no arguments are provided)
function getmonth($m=0) {
return (($m==0 ) ? date(”F”) : date(”F”, mktime(0,0,0,$m)));
}
Examples (the first one; if posted today):
echo getmonth();
// January
echo getmonth(12);
// December
echo getmonth(14);
// February
(since the passed argument is above 12 it starts with January on 13, February on 14, etc etc)
January 16th, 2006 at 12:02 am
You are absolutely righ of course, and this snippet comes from my ‘old days’ as a newbie PHP programmer, when I hadn’t heard of the date() function yet.
Thanks for the comment!