LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   transform month number to month name in php (http://www.linuxquestions.org/questions/programming-9/transform-month-number-to-month-name-in-php-381458/)

ALInux 11-09-2005 11:26 AM

transform month number to month name in php
 
Hi lets say Ive got a number 2 and I want to transform it into Feb but I do not want to create an array with 12 values ....I want a function that does just that .......

deiussum 11-09-2005 11:45 AM

Check out the format strings available with the date function. You can't use it directly to translate 2 to Feb, but you could probably write your own function that pieces it together into a timestamp with mktime and then use that timestamp to format the date with a short textual representation of the month.

Something like so (untested):
Code:

function GetMonthString($n)
{
    $timestamp = mktime(0, 0, 0, $n, 1, 2005);
   
    return date("M", $timestamp);
}



All times are GMT -5. The time now is 07:26 AM.