Reputation: 13
Im having a problem with php date subtracting 1 month in the current date
i got this code.
$date = date("Y-m-d H:i:s", strtotime("-1 month"));
echo $date;
with a result of this? am i missing something.
2016-03-01 23:21:20
Upvotes: 1
Views: 112
Reputation: 781726
Today is March 30. 1 month ago was February 30. But February only had 29 days this year, so February 30 is the same as March 1.
You'll run into the problem on the following days, because that day of the month doesn't exist in the previous month:
Upvotes: 4
Reputation: 50898
If you go back one month from 2016-03-30, you get 2016-02-30. However, 2016-02-29 was the last day of February, so it resolves that date to mean 2016-03-01.
Upvotes: 0