Reputation: 475
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?
Upvotes: 1
Views: 230
Reputation: 1526
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
strtotime('last day of this month')
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
Upvotes: 2