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 Create Quiz Comment K Kanchan_Ray Follow 0 Improve K Kanchan_Ray Follow 0 Improve Article Tags : Web Technologies PHP PHP-date-time PHP-function Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like