How to get the number of the previous month in PHP

1 Answer

0 votes
$currentDate = new \DateTime();

$currentDate->modify('first day of previous month');

$previousMonthNumber = intval($currentDate->format('m'));

echo $previousMonthNumber;

/*
run: 

6

*/

 



answered Jul 14, 2017 by avibootz
...