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

H

How Can We Help?

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

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 monthin 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)

About the author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me