Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP convert month-number to short month-name [duplicate]

Tags:

php

I need to convert month-number to short month-name (i.e., 1 for Jan, 2 for Feb)

I know that I can achieve this via Array, but is there any other way to do it?

Help appreciated.

Thanks.

like image 305
I-M-JM Avatar asked Dec 03 '22 03:12

I-M-JM


1 Answers

Yes there is. Use date/stftime in combination with mktime to create a timestamp within the desired month.

Strftime is cool because it will read the locale setting, and output your written date parts in that specific language.

For example:

$time = mktime(0, 0, 0, $monthNumber);
$name = strftime("%b", $time);

Now lets say you want your short month names in german language you call setlocale before calling strftime:

setlocale(LC_TIME, 'de_DE');
like image 53
fresskoma Avatar answered Dec 18 '22 01:12

fresskoma