I have used the below PHP function to get the previous month,
$currmonth = date(\'m\', strtotime(\'-1 month\'));
It was working fine and I
Literally ask strtotime for the 'first day of the previous month' this makes sure it selects the correct month:-
strtotime
$currmonth = date("m", strtotime("first day of previous month"));