In this post focused on how to get month name from date in php. If you want to find out how to get full month name from date in PHP then i will give simple example with solution. We will look at example of get month short name from date in php. In this post, we will implement a php get month name from number.
We will explain below example to get month name from date in PHP.
- PHP get full month name from date
- PHP get full month name from current date
- PHP get short month name from date
- PHP get short month name from current date
- PHP get month name from number
Read also: How to get file size in PHP?
How to get month name from date in PHP?
You can get the full and short names from a date in PHP using the date() function or the DateTime class. Let’s start useful example.
Example 1: PHP get full month name from date
<?php
$fullDate = "2022-12-08";
$newDate = date('F', strtotime($date));
echo $newDate;
?>
- strtotime($fullDate): Converts the string date into a timestamp.
- date(‘F’): It is return the full month name .
Output:
December
Example 2: PHP get full month name from current date
<?php
$monthName = date('F');
echo $monthName; /* Output: Current Month name */
?>
3. PHP get short month name from date
<?php
$fullDate = "2022-12-08";
$newDate = date('M', strtotime($fullDate));
echo $newDate;
?>
Output:
Dec
4. PHP get short month name from current date
<?php
$newDate = date('M');
echo $newDate; /* Output: Short current month name */
?>
5. PHP get month name from number
<?php
$numberOfMonth = 5;
$monthName = date('F', mktime(0, 0, 0, $numberOfMonth, 10));
echo $monthName;
?>
Output:
May
I hope this tutorial help you.