PHP Date_modify () function

PHP

Syntax:
date_modify (DateTime $object, string $modify);
Parameters:
This function takes two parameters, as described below:
  • $object : This parameter is required. It defines the DateTime object returned by by the date_create() function. This object is modified by the above function.
  • $modify : This is also a required parameter. This defines the date / time string. It grows or shrinks to change the DateTime object.
  • Return Values ​​:
    This function returns a Object DateTime on success. And returns FALSE on failure.The programs below illustrate the date_modify() function:Program 1 :
    // PHP illustration program date_modify()
    // function 
    // create a DateTime object $date = date_create ( "2018-04- 08 " );  
    // call the date modification function
    // with two required parameters date_modify ( $date , "+ 15 days" );  
    // print the modified date in ymd format echo date_format ( $date , "Ymd" ); ?>
    Output:
    2018-04-13
    Program 2 : This program will grow by one months
    // PHP illustration program date_modify()
    // function 
    // create a DateTime object $date = date_create ( '2000-10-14' );  
    // call the date_modify function with
    // two required parameters date_modify ( $date , '+1 month' );  
    // print the modified date echo date_format ( $date , 'Ymd' ); ?>
    Output:
    2000-11-14
    Link
    http://php.net/manual/en/datetime.modify.php