Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

date_sub

Description

The date_sub of Date / Time for PHP subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object.

Syntax

date_sub ( DateTime $object , DateInterval $interval ) : DateTime

Parameters

object

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

interval

A DateInterval object

Return

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

Examples

1 · object interval

<?

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

date_sub($object, $interval);

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

?>
2023-05-10 07:05:20

2 · Return

<?

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

$return = date_sub($object, $interval);

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

?>
2023-05-10 07:05:20
HomeMenu