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.
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With