How to convert number to month name in PHP?

PHP

Nicesnippets

3168

06-01-2021


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