Friday 2 August 2019

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)

0 comments:

Post a Comment