PHP | DateTimeImmutable add() Function Last Updated : 10 Oct, 2019 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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. php <?php // PHP program to illustrate DateTimeImmutable::add() // function // Creating a new DateTimeImmutable::add() object $datetime = new DateTimeImmutable("2019-10-03T10:00:00"); // Initializing a date interval of 2 days $interval = 'P2D'; // Calling the add() function $datetime = $datetime->add(new DateInterval($interval)); // Getting a new date time in the // format of 'Y-m-d H:i:s' echo $datetime->format('Y-m-d H:i:s'); ?> Output: 2019-10-05 10:00:00 Program 2: This program uses DateTimeImmutable::add() function to add 'P2Y5M2DT0H30M40S' DateInterval to the DateTimeImmutable object. php <?php // PHP program to illustrate DateTimeImmutable::add() // function // Creating a new DateTimeImmutable::add() object $datetime = new DateTimeImmutable("2019-10-03T10:00:00"); // Initializing a DateInterval object $interval = 'P2Y5M2DT0H30M40S'; // Calling the add() function $datetime = $datetime->add(new DateInterval($interval)); // Getting a new date time in the // format of 'Y-m-d H:i:s' echo $datetime->format('Y-m-d H:i:s'); ?> Output: 2022-03-05 10:30:40 Reference: https://www.php.net/manual/en/datetimeimmutable.add.php Comment More infoAdvertise with us Next Article PHP | DateTimeImmutable add() Function K Kanchan_Ray Follow Improve Article Tags : Web Technologies PHP PHP-date-time PHP-function Similar Reads PHP | DateTimeImmutable::sub() Function The DateTimeImmutable::sub() function is an inbuilt function in PHP which is used to subtract a number of days, months, years, hours, minutes and seconds from a created DateTimeImmutable object. Syntax: DateTimeImmutable::sub( interval ) Parameters: This function accepts a parameter interval which i 2 min read PHP | DateTimeImmutable modify() Function The DateTimeImmutable::modify() function is an inbuilt function in PHP which is used to modify or alter the timestamp of the created DateTimeImmutable object. Syntax: DateTimeImmutable DateTimeImmutable::modify( string $modify ) Parameters: This function uses two parameters as mentioned above and de 2 min read PHP | DateTime add() Function The DateTime::add() function is an inbuilt function in PHP which is used to add an amount of time (days, months, years, hours, minutes and seconds) to the given DateTime object. Syntax: Object oriented style: DateTime DateTime::add( DateInterval $interval ) Procedural style: DateTime date_add( DateT 2 min read PHP | DateTimeImmutable setDate() Function The DateTimeImmutable::setDate() function is an inbuilt function in PHP which is used to set a new date in the created DateTimeImmutable object. Syntax: DateTimeImmutable DateTimeImmutable::setDate( int $year, int $month, int $day ) Parameters: This function accepts three parameters as mentioned abo 2 min read PHP | DateTimeImmutable setISODate() Function The DateTimeImmutable::setISODate() function is an inbuilt function in PHP which is used to sets the ISO (International Organization for Standardization ) date into the created DateTimeImmutable object. This function sets the date according to the ISO 8601 standard, using weeks and day offsets rathe 2 min read Like