Open In App

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.
Output:
2019-10-07
Program 2: This program modify the given date with the increment of 2 months.
Output:
2019-12-02
Reference: https://www.php.net/manual/en/datetimeimmutable.modify.php

Next Article

Similar Reads