I saw this code here on stack overflow
function add($date_str, ${
$date = new DateTime($date_str);
$start_day = $date->format('j');
$date->modify("+{$months} month");
$end_day = $date->format('j');
if ($start_day != $end_day)
$date->modify('last day of last month');
return $date;
}
$result = add('2011-01-28', 1); // 2011-02-28
$result = add('2011-01-31', 3); // 2011-04-30
Which increments the date but does not exceed the last day of the month. But when i try to run the function using
$dues=add('2011-01-28', 1); echo $dues;
It returns an "Object of class DateTime could not be converted to string" error? But it seems that it works for other people.