How to get month name from date in PHP?

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.

  1. PHP get full month name from date
  2. PHP get full month name from current date
  3. PHP get short month name from date
  4. PHP get short month name from current date
  5. PHP get month name from number
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.

Jasminkumar Borad
Jasminkumar Borad

I'm a full-stack developer, enterpreneur and owner of webstuffsolution.com. I live in india and i like to write tutorial and tips that can help to other user. I like to share various programming language tips and solution. I believe in hardworking and consistency.

Leave a Reply

Your email address will not be published. Required fields are marked *