How to convert number to month name in PHP?

Jan 06, 2021

.

Admin

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...

#PHP