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");

?>
2023-09-22 04:21:10

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' => '2023-09-22 04:21:10.324774',
   'timezone_type' => 3,
   'timezone' => 'UTC',
))

PHP

Home Menu