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:
The function accepts two parameters as described below:
- $object : This is a mandatory parameter. It specifies a DateTime object returned by date_create() .This object is modified by the above mentioned function.
- $modify : This is also a mandatory parameter. This specifies a date/time string. It is incremented or decremented to modify the DateTime object.
Return Values :
This function returns a DateTime object on success. And returns FALSE on failure.
Below programs illustrate the date_modify() function :
Program 1 :
<?php
$date =date_create( "2018-04-08" );
date_modify( $date , "+15 days" );
echo date_format( $date , "Y-m-d" );
?>
|
Output:
2018-04-13
Program 2: This program will be increase months by one
<?php
$date = date_create( '2000-10-14' );
date_modify( $date , '+1 month' );
echo date_format( $date , 'Y-m-d' );
?>
|
Output:
2000-11-14
Reference
http://php.net/manual/en/datetime.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!