PHP | DateTime modify() Function Last Updated : 10 Oct, 2019 Comments Improve Suggest changes Like Article Like Report 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: This function uses two parameters as mentioned above and described below: $object: It specifies the DateTime object returned by date_create() function. This object is modified by DateTime::modify() function. $modify: It specifies the date/time string. It is incremented or decremented to modify the DateTime object. Return Value: This function returns the modified DateTime object on success or False on failure. Below programs illustrate the DateTime::modify() function in PHP: Program 1 : php <?php // PHP program to illustrate // DateTime::modify() function // Creating a DateTime object $datetime = new DateTime('2019-09-30'); // Calling of date DateTime::modify() function // with the increment of 5 days as parameters $datetime->modify('+5 day'); // Getting the modified date in "y-m-d" format echo $datetime->format('Y-m-d'); ?> Output: 2019-10-05 Program 2: php <?php // PHP program to illustrate the // DateTime::modify() function // Creating a DateTime object $datetime = new DateTime('2019-09-30'); // Calling of date DateTime::modify() function // with the increment of 5 months as parameters $datetime->modify('+5 month'); // Getting the modified date in "y-m-d" format echo $datetime->format('Y-m-d'); ?> Output: 2020-03-01 Reference: https://www.php.net/manual/en/datetime.modify.php Comment More infoAdvertise with us Next Article PHP | DateTime modify() Function K Kanchan_Ray Follow Improve Article Tags : Web Technologies PHP PHP-date-time PHP-function Similar Reads 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 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 | 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 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 PHP | DateTimeZone::getName() Function The DateTimeZone::getName() function is an inbuilt function in PHP which is used to return the name of the created timezone. Syntax: DateTimeZone::getName() Parameters: This function does not accept any parameter. Return Values:: This function return the name of the created timezone. Below programs 1 min read PHP | DateTime setDate() Function The DateTime::setDate() function is an inbuilt function in PHP which is used to reset the current date of DateTime object with the given date-time object. Syntax: Object oriented style: DateTime DateTime::setDate( int $year, int $month, int $day ) Procedural style: DateTime date_date_set( DateTime $ 2 min read PHP | date_sun_info() Function The date_sun_info() is an inbuilt function in PHP which is used to find the information about sunset/sunrise and twilight begin/end for a specified day and location.Syntax: array date_sun_info($timestamp, $latitude, $longitude) Parameters: This function accepts three parameters as mentioned above an 2 min read PHP | easter_date() Function The easter_date() function is a built-in function in PHP which returns the Easter date in the year passed as an argument. The current year is taken as default year when no arguments are passed as parameter. Syntax: easter_date( $year ) Parameter: The function accepts one optional parameter $year whi 2 min read Like