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)
07-02-23 22:50:49 05-13-24 02:56:01
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