strtotime() works exactly . The problem is that you are asking her to return.
"- 1 month" does not match the "previous month". This is the same as "subtract 1 from the current month, and then normalize the result."
In 2017-05-31 subtracting 1 from the current month receives 2017-04-31 , which is not a valid date. After normalization, it becomes 2017-05-01 , hence the result is obtained.
There are several ways to get the desired value. For instance:
// Today $now = new DateTime('now'); // Create a date interval string to go back to the first day of the previous month $int = sprintf('P1M%dD', $now->format('j')-1); // Get the first day of the previous month as DateTime $fdopm = $now->sub(new DateInterval($int)); // Verify it works echo($fdopm->format('Ym-d')); // On 2017-05-31 it should print: // 2017-04-01
axiac source share