PHP | DateTimeImmutable modify() Function Last Updated : 10 Oct, 2019 Comments Improve Suggest changes Like Article Like Report 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 described below: object: This parameter holds the DateTime object returned by date_create() function. $modify This parameter holds the date/time string which is set of times to alter the given DataTimeImmutable object. Return Values: This function returns the modified DateTimeImmutable object on success or False on failure. Below programs illustrate the DateTimeImmutable::modify() function in PHP: Program 1: This program modify the given date with the increment of 5 days. php <?php // PHP program to illustrate DateTimeImmutable::modify() // function // creating a DateTime object $datetimeImmutable = new DateTimeImmutable('2019-10-02T00:00:00'); // Calling of date DateTimeImmutable::modify() function // with the increment of 5 days as parameters $newDateTimeImmutable = $datetimeImmutable->modify('+5 days'); // Getting the modified date in "y-m-d" format echo $newDateTimeImmutable->format('Y-m-d'); ?> Output: 2019-10-07 Program 2: This program modify the given date with the increment of 2 months. php <?php // PHP program to illustrate DateTimeImmutable::modify() // function // Creating a DateTime object $datetimeImmutable = new DateTimeImmutable('2019-10-02T00:00:00'); // Calling of date DateTimeImmutable::modify() function // with the increment of 2 months as parameters $newDateTimeImmutable = $datetimeImmutable->modify('+2 months'); // Getting the modified date in "y-m-d" format echo $newDateTimeImmutable->format('Y-m-d'); ?> Output: 2019-12-02 Reference: https://www.php.net/manual/en/datetimeimmutable.modify.php Comment More infoAdvertise with us Next Article PHP | DateTimeImmutable modify() Function K Kanchan_Ray Follow Improve Article Tags : Web Technologies PHP PHP-date-time PHP-function Similar Reads 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 | 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 | 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 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 | date_modify() Function The date_modify() function is an inbuilt function in PHP. Through the help of this function, we can modify or can alter the timestamp of DateTime object. The DateTime object and string modify are parameters in the calling function. Syntax: date_modify(DateTime $object, string $modify); Parameters: T 2 min read Like