Anonymous user / 3.239.3.196 Log In Register
?
Wallet: 3.00
Daily Credits:
1.20 / 1.20

PHP Functions Online


DateTime::sub

(PHP 5 >= 5.3.0)

DateTime::sub -- date_sub Subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object

public DateTime $object->sub(DateInterval $interval)
public DateTime::__construct([string $time = "now"[, DateTimeZone $timezone = NULL]])
public DateTimeZone::__construct(string $timezone)
public DateInterval::__construct(string $interval_spec)

Checkout ? #

Item Description Item Price Your Price
Total

Preview #

${{ variable.param.name }} = {{ variable.param|getValue:variable.form:true }};
{{ call.result}} = ;

Tip: You can change some values by clicking on it in the preview above.

Description #

public DateTime DateTime::sub ( DateInterval $interval )

Subtracts the specified DateInterval object from the specified DateTime object.

Parameters #

interval

A DateInterval object

Return Values #

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

Examples #

Example #1 DateTime::sub() example

Object oriented style

<?php
$date 
= new DateTime('2000-01-20');
$date->sub(new DateInterval('P10D'));
echo 
$date->format('Y-m-d') . "\n";
?>

Procedural style

<?php
$date 
date_create('2000-01-20');
date_sub($datedate_interval_create_from_date_string('10 days'));
echo 
date_format($date'Y-m-d');
?>

The above examples will output:

2000-01-10

Notes #

DateTime::modify() is an alternative when using PHP 5.2.

See Also #