I am explaining you, we will learn how to get the month name from the date in PHP. The PHP provides very useful functions by using it we can easily format the date.
Example 1: Extract Month Name From Date
In this example, we have used the createFromFormat() function which helps us to provide month name from the specific date.
<?php
$dateTime = DateTime::createFromFormat('d/m/Y', '10/04/2005');
echo $dateTime->format('F'); //April
echo "<br/>";
echo $dateTime->format('M'); //Apr
?>
Result:
April
Apr
Example 2: Extract Month Name Using date() Function
I am explaining you, If you don’t want to use the DateTime class then you can use the PHP’s date() function for get the month name from date.
<?php
// Date Format: Y/m/d
$CustomDate = '2015/01/04';;
echo $month = date('F', strtotime($CustomDate));//January
echo "<br/>";
echo $month = date('M', strtotime($CustomDate));//Jan
?>
Result:
January
Jan
Hello, Welcome to webdeveloperindia.in. I am a full-stack web developer. Email – [email protected] | Skype – azaruddin23. I have knowledge of PHP, Laravel, Magento 1/2, Codeigniter, WordPress, Joomla, Shopify, Git, Bitbuket, jQuery, Ajax, Javascript and ReactJS.