ASPit - Totally ASP JSit - Totally JavaScript
Search PHPit

Use this textbox to search for articles on PHPit. Seperate keywords with a space.

Advertisements

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==) ? date(”F”) : date(”F”mktime(0,0,0,$m)));
}
?>

2 Responses to “Get month name”

  1. BraveBrain Says:

    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)

  2. Dennis Pallett Says:

    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!

Leave a Reply