0

$oldm='5';
I want $oldm to convert to a new variable $newm, so that $newm contains "may". I mean i want to convert $oldm to text month. How to do it ?

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by kylegetson
0

Create an array with all the months in it. Then if 5 is supplied as the month, just access the 5th element of the array.

You may want to put a dummy value in location 0 of the array so it makes it a bit easier to access the correct array key. E.g.

$months = array('dummy','Jan','Feb','Mar','April','May','June','July','Aug','Sept','Oct','Nov','Dec');

$oldm = 5;
$newm = $months[$oldm];
0

Use this, you won't have to type up the months. This creates a string '5/1/2010' and then converts it to a timestamp, and passes it into the date function with the 'F' as the format, which will output the text version of the month.

$oldm = 5;
$newm = date( 'F', strtotime( $oldm . '/1/' . date('Y') ) );

doing it this way makes it easier to maintain. If you later want to change to month abbreviations, you could just change 'F' to 'M', no changing an array of months.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.