Syntax: Parameters:this function uses two parameters as above and described below:
- $object:specifies the DateTime object returned by the date_create() function. This object is modified by the DateTime::modify() function.
- $modify:specifies a date / time string. It grows or shrinks to modify the DateTime.
Return Value:This function returns the modified DateTime on success, or False on error.The following programs illustrate the DateTime::modify() function in PHP:
Program 1 :
// PHP illustration program
// DateTime::modify() function
// Create DateTime object
$datetime
=
new
DateTime (
’2019-09-30’
);
// Call the function date DateTime::modify()
// with a step of 5 days as parameters
$datetime
-> modify (
’+5 day’
);
// Get the modified date in ymd format
echo
$datetime
-> format ( ’Ymd’
);
?>
Exit:2019-10 -05
Program 2:
// PHP illustration program
// DateTime::modify() function
// Create a DateTime object
$datetime
=
new
DateTime (
’ 2019-09-30’
);
// Call the function date DateTime::modify()
// with a step of 5 months as parameters
$datetime
-> modify (
’+5 month’
);
// Get the modified date in ymd format
echo
$datetime
-> format ( ’Ymd’
);
?>
Exit:2020-03 -01
Link: https://www.php. net / manual / en / datetime.modify.php