Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get month of a given date

Tags:

php

Get month of a given date which is stored in a PHP time variable in 'Y-m-d' format

like image 450
nullpointerexception Avatar asked Aug 13 '10 06:08

nullpointerexception


People also ask

What does the getMonth () method of the date object return?

The getMonth() method returns the month in the specified date according to local time, as a zero-based value (where zero indicates the first month of the year).


2 Answers

Try date_parse_from_format():

$date = "2010-08-12";
$d = date_parse_from_format("Y-m-d", $date);
echo $d["month"];
like image 180
Bill Karwin Avatar answered Sep 21 '22 08:09

Bill Karwin


$date = "2010-10-10";
echo date("m", strtotime($date))?>
like image 27
Adnan Avatar answered Sep 21 '22 08:09

Adnan