Connecting Tech Pros Worldwide Forums | Help | Site Map

month name predefined function?

laredotornado@zipmail.com
Guest
 
Posts: n/a
#1: Jul 17 '05
Hello, I'm using PHP 4. Is there a predefined function for returning
the name of the month given the input of the month represented as a
number between 1 and 12?

Thanks, - Dave


Ewoud Dronkert
Guest
 
Posts: n/a
#2: Jul 17 '05

re: month name predefined function?


On 30 Apr 2005 08:43:06 -0700, laredotornado@zipmail.com wrote:[color=blue]
> the name of the month given the input of the month represented as a
> number between 1 and 12?[/color]

Not easily, and only in English. You could use

echo date( 'F', mktime( 12, 0, 0, $month, 1, 2000, 0 ) );

(Use midday to avoid problems with daylight saving time).
Easier and less error prone would be

$monthname = array( 1 => 'January', 'February', 'March', <etc> );
echo $monthname[$month];


--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
johnjawed@gmail.com
Guest
 
Posts: n/a
#3: Jul 17 '05

re: month name predefined function?


I would just do it as this:

<?PHP
$intMonth = 3; // March
printf("%s",date("M", mktime(0, 0, 0, $intMonth, 1, 2000));
?>

Closed Thread