The DateTimeImmutable::add() function is an inbuilt function in PHP which is used to add a number of days, months, years, hours, minutes and seconds to a created DateTimeImmutable object.
DateTimeImmutable DateTimeImmutable::add( DateInterval $interval )
Parameters: This function accepts a single parameter $interval which holds the number of days or months or years or hours or minutes or seconds which are going to be added to the given DateTimeImmutable object.
Return Values: This function returns the final DateTimeImmutable object after addition is done.
Below programs illustrate the DateTimeImmutable::add() function in PHP:
Program 1: This program uses DateTimeImmutable::add() function to add 2 days to the DateTimeImmutable object.
Program 2: This program uses DateTimeImmutable::add() function to add ‘P2Y5M2DT0H30M40S’ DateInterval to the DateTimeImmutable object.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.