How to convert number to month name in PHP?

Admin   PHP   112  2021-03-18 04:10:01

Hi Guys,

In this example,I will learn you how to convert number to month name in php.you can easy nad simply convert number to month name in php.

The DateTime::createFromFormat() function is an inbuilt function in php which is used to parses a time string according to a specified format. This function accepts three parameters and returns new DateTime in success or false on failure.

Example:

 

<?php

$monthNum = 5;

$dateObj = DateTime::createFromFormat('!m', $monthNum);

$monthName = $dateObj->format('F');

echo $monthName;

?>

Output:

 

May

It will help you...