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:
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
$datetime = new DateTime( '2019-09-30' );
$datetime ->modify( '+5 day' );
echo $datetime ->format( 'Y-m-d' );
?>
|
Program 2:
<?php
$datetime = new DateTime( '2019-09-30' );
$datetime ->modify( '+5 month' );
echo $datetime ->format( 'Y-m-d' );
?>
|
Reference: https://www.php.net/manual/en/datetime.modify.php
Last Updated :
10 Oct, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...