I'm using code that works fine on all dates, except 2015-05-31. The code brings me the first day of next month. it works on every date, even if day of month is 31.
$time = strtotime('2015-07-31');
$final = date("Y-m-1", strtotime("+1 month", $time));
echo $final;
output will be --> 2015-08-1.
For some reason on the date 2015-05-31 it returns 2015-07-1 instead of 2015-06-01
$time = strtotime('2015-05-31');
$final = date("Y-m-1", strtotime("+1 month", $time));
echo $final;
Its probably because 6-2014 has 30 days, and 8-2014 has 31 days, so +1 month adds 30 days and not a "month".
How could i get correctly the first day of next month on every date?
Thank you.