How to Get Month Name from Date using PHP?
In this tutorial, we will learn How to Get a Month’s Name from Date using PHP?. In most of the cases we have questions about how to get the month name from the date function, then I will give how to Get the Month Name from Date simple example with a solution. I will give you an example of getting a month short name from the date function in PHP.
Also read: How to Get Yesterday Date using PHP?
I will give you a simple example of how to get the full month name from the date function. so let’s start examples with output:
Consent
- Get Full Month Name from Date
- Get Full Month Name from Current Date
- Get Short Month Name from Date
- Get Month Name from Number
Get Full Month Name from Date
<?php
#index.php
$date = "2021-12-01";
$new_date = date('F', strtotime($date));
echo $new_date;
?>
Output: December
Get Full Month Name from Current Date
Also read: How to Get Full Day Name from Date using PHP
<?php
#index.php
$new_date = date('F');
echo $new_date;
?>
Output: November
Get Short Month Name from Date
<?php
#index.php
$date = "2021-12-01";
$new_date = date('M', strtotime($date));
echo $new_date;
?>
Output: Dec
Get Short Month Name from Current Date
<?php
#index.php
$new_date = date('M');
echo $new_date;
?>
Output: Nov
Get Month Name from Number
Also read: How to Get Next Month Date using PHP?
<?php
#index.php
$month_number = 6;
$month_name = date('F', mktime(0, 0, 0, $month_number, 10));
echo $month_name;
?>
Output: June