WE will learn how to add date time intervals to a date object. We must understand date interval and date format before using add function to the date object.
Output is here ( Refresh this page to see the change in output)
01-06-23 00:04:43 09-06-24 04:09:55
Using DateTimeImmutable object
DateTimeImmutable never modifies itself but returns a new object instead
$date1=new DateTime('2019-05-30'); // date object created.
$date1->add(new DateInterval('P1Y3M')); // inerval of 1 year 3 months added
echo $date1->format('Y-M-d'); // Output is 2020-Aug-30
/// by using DateTimeImmutable ///
$date1=new DateTimeImmutable('2019-05-30'); // date object created .
$date1->add(new DateInterval('P1Y3M')); // inerval of 1 year 3 months added
echo $date1->format('Y-M-d'); // Output is 2019-May-30