tags:

views:

24

answers:

2

I am using the following code in php to convert the month in numeric to textural representation.

date('M',strtotime(8));

But for every digit I am getting 'Dec' as my month.

How should i make it work.

Thank you Zeeshan

+3  A: 

But for every digit I am getting 'Dec' as my month.

That's no surprise: strtotime(8) will give you 0 - and that is January 1st, 1970, 0:00:00 UTC, in your local time zone (where it was still december at that point).

You could use

$month = 8;
date("M", strtotime("1970-$month-01"));

(the 1970 is totally irrelevant - it could be any year.)

Alternatively, maybe more beautifully, use mktime() as shown by nikic.

Pekka
+2  A: 

strtotime expects a date string, not a single month. You may use mktime to create your month:

 date('M', mktime(0, 0, 0, $month));
nikic