0

How do i properly minus 1 month for the current month ?

$current_month1  = date('m'); 
$current_month  = $current_month1-1;
echo $current_month;

//current ouput
6
//desired output
06
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
gtroop
  • 295
  • 4
  • 13

3 Answers3

3

check the following:

$now = new \DateTime("now");
$past = $now->modify("-1 month");

DateTime::modify docs

Also you can do it using DateInterval, the docs has example.

katona.abel
  • 771
  • 4
  • 12
2

You can use date in combination with strtotime for this.

echo date('m', strtotime('last month')); // 06
Jerodev
  • 32,252
  • 11
  • 87
  • 108
1

The m operator in date will get you:

echo date('m', strtotime('now - 1 month'));

Gives 06.

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252