How to Get Month Name from Date in PHP?

By Hardik Savani May 14, 2024 Category : PHP

This example is focused on how to get month name from date in php. if you have question about 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 article, we will implement a php get month name from number.

I will give you very simple example how to get month name from date in PHP. so let's see several examples with output:

Example 1: PHP Get Full Month Name from Date

index.php

<?php

$date = "2021-02-02";

$newDate = date('F', strtotime($date));

echo $newDate;

?>

Output:

February

Example 2: PHP Get Full Month Name from Current Date

index.php

<?php

$newDate = date('F');

echo $newDate;

?>

Output:

November

Example 3: PHP Get Short Month Name from Date

index.php

<?php

$date = "2021-02-02";

$newDate = date('M', strtotime($date));

echo $newDate;

?>

Output:

Feb

Example 4: PHP Get Short Month Name from Current Date

index.php

<?php

$newDate = date('M');

echo $newDate;

?>

Output:

Nov

Example 5: PHP Get Month Name from Number

index.php

<?php

$monthNumber = 4;

$monthName = date('F', mktime(0, 0, 0, $monthNumber, 10));

echo $monthName;

?>

Output:

April

i hope it can help you...

Tags :
Shares