PHP | DateTime add() Function Last Updated : 10 Oct, 2019 Comments Improve Suggest changes Like Article Like Report 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( DateTime $object, DateInterval $interval ) Parameters: This function uses two parameters as mentioned above and described below: $object: It specifies the DateTime object returned by date_create() function. This function returns a new DateTime object. $interval: This parameter holds the DateInterval object. Return Value: This function returns the new DateTime object after changing on success or False on failure. Below programs illustrate the DateTime::add() function in PHP: Program 1: php <?php // Initialising a DateTime $datetime = new DateTime('2019-09-30'); // DateInterval object is taken as the // parameter of the add() function // Here 1 day is added $datetime->add(new DateInterval('P1D')); // Getting the new date after addition echo $datetime->format('Y-m-d') . "\n"; ?> Output: 2019-10-01 Program 2: php <?php // Initialising a DateTime $datetime = new DateTime('2019-09-30'); // DateInterval object is taken as the // parameter of the add() function // Here 5 hours, 3 Minutes and 10 seconds is added $datetime->add(new DateInterval('PT5H3M10S')); // Getting the new date after addition echo $datetime->format('Y-m-d H:i:s') . "\n"; ?> Output: 2019-09-30 05:03:10 Reference: https://www.php.net/manual/en/datetime.add.php Comment More infoAdvertise with us Next Article PHP | DateTime add() Function K Kanchan_Ray Follow Improve Article Tags : Web Technologies PHP PHP-date-time PHP-function Similar Reads PHP | DateTimeImmutable add() Function 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 s 2 min read PHP | DateTime sub() Function The DateTime::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 DateTime object. Syntax: Object oriented style: DateTime DateTime::sub( DateInterval interval ) Procedural style: DateTime date_sub( DateTim 2 min read PHP | DateTime diff() Function The DateTime::diff() function is an inbuilt function in PHP which is used to return the difference between two given DateTime objects. Syntax: Object oriented style: DateInterval DateTime::diff( DateTimeInterface $datetime2, bool $absolute = FALSE ) or DateInterval DateTimeImmutable::diff( DateTimeI 2 min read PHP | DateTime modify() Function The DateTime::modify() function is an inbuilt function in PHP which is used to modify or can alter the timestamp of a DateTime object. Syntax: Object oriented style: DateTime DateTime::modify( string $modify ) Procedural style: DateTime date_modify( DateTime $object, string $modify ) Parameters: Thi 2 min read PHP | DateTime format() Function The DateTime::format() function is an inbuilt function in PHP which is used to return the new formatted date according to the specified format. Syntax: Object oriented style string DateTime::format( string $format ) or string DateTimeImmutable::format( string $format ) or string DateTimeInterface::f 1 min read Like