-2

I have tried :

$firstOfMonth = "2015-01-01";
$last_month = date("Y-m-d", strtotime('first day of -1 month', strtotime($firstOfMonth)));
                                    /* ^^^^^ This gives me 01 of last month */
/*** Tried 'seventh day of -1 month'
/*   it gives 1970-01-01
*/

What I want is to get the 07 of last month.

Alex
  • 626
  • 7
  • 16

2 Answers2

2

uhm....the first day of a month is allways 01....so basically you only need year and month:

$firstOfMonth = "2015-01-01";
$last_month = date("Y-m-01",strtotime("-1 month",strtotime($firstOfMonth)));
Mr.Manhattan
  • 5,315
  • 3
  • 22
  • 34
0

Just like Mr.Manhattan said, you just need the year and month and to the seventh day you can leave it hard coded or in a variable:

date("Y-m-07",strtotime("-1 month"));
$fixedDay = '07';
echo date("Y-m-$fixedDay",strtotime("-1 month"));
Rizier123
  • 58,877
  • 16
  • 101
  • 156
Paulo Lima
  • 76
  • 9