0

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

Dharman
  • 30,962
  • 25
  • 85
  • 135

2 Answers2

0

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
aynber
  • 22,380
  • 8
  • 50
  • 63
-1

Should be simple as below.

<?php
$month_end = strtotime('last day of next month', time());
echo date('D, M jS Y', $month_end).'<br/>';

?>
dweb
  • 141
  • 7