date_modify

Alters the timestamp

Syntax

date_modify ( DateTime $object , string $modify ) : DateTime

Parameters

object

A DateTime object returned by date_create(). The function modifies this object.

modify

A date/time string. Valid formats are explained in Date and Time Formats.

Return

Returns the DateTime object for method chaining or FALSE on failure.

Examples

object modify

<?

$object = date_create();
$modify = "1 year 1 month 1 week 1 day 1 hour 1 minute 1 second";

date_modify($object, $modify);

echo date_format($object, "Y-m-d H:i:s");

?>
2022-11-26 14:39:06

Return

<?

$object = date_create();
$modify = "1 year 1 month 1 week 1 day 1 hour 1 minute 1 second";

$return = date_modify($object, $modify);

var_export($return);

?>
DateTime::__set_state(array(
   'date' => '2022-11-26 14:39:06.801238',
   'timezone_type' => 3,
   'timezone' => 'UTC',
))

PHP

Home Menu