1

So far with

strtotime('last day of this month');

gives me the last day (31), but I want the penultimate (30), and I've tried with:

strtotime('-1 day','last day of this month');

Also with strtotime('last day of this month') - strtotime('1 day'); and other things. Always results in (formatted with date()) 31-dec-1969.

How can I achieve this?

Epistomai
  • 455
  • 1
  • 6
  • 16

1 Answers1

2

You're almost there. strtotime() expects parameter 2 to be an integer in case of subtracting a time span from a date. So you need to

  1. convert the last day of the month to an integer timestamp value using strtotime('last day of this month')
  2. Then subtract a day from it by doing strtotime('-1 day', $valueFromStep1)

Hence doing

strtotime('-1 day',strtotime('last day of this month'))

Gives the expected answer

Here is a similar question to the one you have asked: Subtract 1 day with PHP

strtotime reference: http://php.net/manual/en/function.strtotime.php

S Raghav
  • 1,386
  • 1
  • 16
  • 26