Home PHP How to transform a month number to the relevant month name using PHP?
 
 
 

How to transform a month number to the relevant month name using PHP?

PDF Print E-mail

Question: How to transform a month number to the relevant month name using PHP?

 

Answer:

This can be obtained by combining the date function with the mktime function

For example if I want to get Jan from the number 1 which represents the first month in the year I would use something similar to the below

 
$i = 1; //The number 1 represents January
 
echo date("M",mktime(0,0,0,$i,1,2010)); //This will output Jan
 

So if you want to output Feb the value of $i would be 2 etc

 

USAGE:

date = string date ( string $format [, int $timestamp ] ) (PHP 4 & 5)


mktime = 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 ]]]]]]] )  (PHP 4 & 5)

+/-
+/- Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
Security Please input the anti-spam code that you can read in the image.
 

Go Daddy $7.49 .com Sale!