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
$datetimeImmutable = new DateTimeImmutable( '2019-10-02T00:00:00' );
$newDateTimeImmutable = $datetimeImmutable ->modify( '+5 days' );
echo $newDateTimeImmutable ->format( 'Y-m-d' );
?>
|
Program 2: This program modify the given date with the increment of 2 months.
<?php
$datetimeImmutable = new DateTimeImmutable( '2019-10-02T00:00:00' );
$newDateTimeImmutable = $datetimeImmutable ->modify( '+2 months' );
echo $newDateTimeImmutable ->format( 'Y-m-d' );
?>
|
Reference: https://www.php.net/manual/en/datetimeimmutable.modify.php
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
10 Oct, 2019
Like Article
Save Article