Convert number to month name in PHP

Extract PHP numbers from strings
How can I sort arrays and data in PHP?

This solution will teach us how to convert numbers to month names in PHP.

solution 1.

Nowadays, you should really be using DateTime objects for any date/time math.

$monthNum  = 3;
$dateObj   = DateTime::createFromFormat('!m', $monthNum);
$monthName = $dateObj->format('F'); // March

solution 2.

$monthNum  = 3;
$monthName = date('F', mktime(0, 0, 0, $monthNum, 10)); // March

If you want the 3-letter month name like Mar, change F to M. The list of all available formatting options can be found in the PHP manual documentation.

Extract PHP numbers from strings
How can I sort arrays and data in PHP?

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top