Today - 2021-03-31
<?php
echo date("Y-m-t H:i:s", strtotime("+1 month"));
?>
Expected result 2021-04-30
Result 2021-05-31
Today - 2021-03-31
<?php
echo date("Y-m-t H:i:s", strtotime("+1 month"));
?>
Expected result 2021-04-30
Result 2021-05-31
Adding a month adds a certain number of days, so it throws things off. The easiest way is to get the first day of next month, then use t
to format it to the total number of days:
echo date("Y-m-t H:i:s", strtotime("first day of next month")); // 2021-04-30 10:27:35
Should be simple as below.
<?php
$month_end = strtotime('last day of next month', time());
echo date('D, M jS Y', $month_end).'<br/>';
?>