php get month from date – PHP date() Function : Best 5 Ways

php get month from date: here we can using Using date() function, Using strtotime() and date() function, Using DateTime class and Using CreateFromFormat() method to get month from any date with examples

php get month from date Examples

php grab month from date

$last_month = date("m",strtotime($crated_at));

get current month php

current month
//half name in words format
date('M');

//full name in words format
date('F');

//number
date('m');

get current month php

date('m');

datetime get month php

$join_dt = new DateTime();
$last_month = $join_dt->format('m');
print_r($last_month);

get day from date php

// Prints the day
echo "Last".date("l") . "<hr>";

get month from database php

Read Also:  php array to javascript array - How to Convert PHP Array to JavaScript Array?

echo 'Last Day' . date('d', strtotime($data['crated_at']));
echo 'Last Month' . date('m', strtotime($data['crated_at']));
echo 'Last Year' . date('Y', strtotime($data['crated_at']));

Working with datetime in PHP Examples
Working with datetime in PHP Examples

How to Get Month From a Date in PHP?

php get month from date Using strtotime() and date() function to retrieve month from any date

<?php
$crated_at = strtotime("5th September 2022");
echo "First Solution: " . date("m", $crated_at);
echo "<br />";
echo "Second Solution: " . date("M", $crated_at);
echo "<br />";
echo "Third Solution: " . date("n", $crated_at);
?>

Using CreateFromFormat() method to get month from any date

<?php
$crated_at = DateTime::createFromFormat('jS F Y', '5th February 2025');
echo "First Solution: " . $crated_at->format('m');
echo "<br />";
echo "Second Solution: " . $crated_at->format('M');
echo "<br />";
echo "Third Solution: " . $crated_at->format('n');
?>

Using DateTime class to get current month

Read Also:  PHP Laravel 6 PayPal Payment Gateway API integration step by step

<?php
$crated_at = new DateTime();
echo "First Solution:  " . $crated_at->format('m');
echo "<br />";
echo "First Solution:  " . $crated_at->format('M');
echo "<br />";
echo "First Solution:  " . $crated_at->format('n');
?>

Don’t Miss : current month in php

How to get year and month from a date – PHP?

Using date() and strtotime() Examples

$time=strtotime($crated_at);
$month=date("F",$time);
$year=date("Y",$time);

Example

$crated_at = "2023-01-05";

$year = date('Y', strtotime($crated_at));

$month = date('F', strtotime($crated_at));

echo $month

I hope you get an idea about php get month from date.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.