get month from date php code example

Example 1: get last month php

$currentMonth = date('M');// if number, then date('m');
//Last month
$lastMonth = Date("F", strtotime("first day of previous month");
$nextMonth = Date("F", strtotime("first day of next month");

Example 2: get current month php

current month
  //half name in words
  date('M');
//full name in words
date('F');
//number
date('m');

Example 3: php grab month from date

$month = date("m",strtotime($mydate));

Example 4: datetime get month php

$dateTime = new DateTime();
$month = $dateTime->format('m');

Example 5: get month from database php

echo 'Day' . date('d', strtotime($row['Date']));
echo 'Month' . date('m', strtotime($row['Date']));
echo 'Year' . date('Y', strtotime($row['Date']));

Tags:

Sql Example