DateTime::setTimezone
DateTime::__wakeup
DateTime
PHP Manual

# DateTime::sub

(PHP 5 >= 5.3.0)

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

### Descripción

public DateTime DateTime::sub ( DateInterval `$interval` )
DateTime date_sub ( DateTime `$object` , DateInterval `$interval` )

Subtracts the specified DateInterval object from the specified DateTime object.

### Lista de parámetros

`object`

  Procedural style only: A DateTime object returned by date_create()

`interval`

  The amount to be subtracted. For the date use "P3D", "P3M", "P3Y" or a combination of the three e.g. "P2M5D" (Y = Years, M = Months, D = Days.) MUST BE YEAR MONTH DAY FORMAT "P5Y", "P5M2D", "P5Y4D". For the time use "T3H", "T3M", "T3S" or or a combination of the three e.g. "T5H20M" (H = Hours, M = Minutes, S = Seconds). For dateTime us "P5D2M4YT5H20M". The digit before the letter (NOT P or T) can be any amount.

### Valores retornados

Returns the modified DateTime.

### Ejemplos

Example #1 date_sub() example

`<?php
$date = new DateTime("18-July-2008 16:30:30");
echo $date->format("d-m-Y H:i:s").'<br />';
date_sub($date, new DateInterval("P5D"));
echo '<br />'.$date->format("d-m-Y").' : 5 Days';
date_sub($date, new DateInterval("P5M"));
echo '<br />'.$date->format("d-m-Y").' : 5 Months';
date_sub($date, new DateInterval("P5Y"));
echo '<br />'.$date->format("d-m-Y").' : 5 Years';
date_sub($date, new DateInterval("P5Y5M5D"));
echo '<br />'.$date->format("d-m-Y").' : 5 Days, 5 Months, 5 Years';
date_sub($date, new DateInterval("P5YT5H"));
echo '<br />'.$date->format("d-m-Y H:i:s").' : 5 Years, 5 Hours';
?>`

### Notes

Warning

Esta función es EXPERIMENTAL. Esto significa que el comportamiento de esta función, el nombre de esta función y en definitiva TODO lo documentado sobre esta función, puede cambiar en una futura version de PHP SIN AVISO. La advertencia queda hecha, y utilizar esta extensión queda bajo su propia responsabilidad.

### Ver también

- DateTime::add() - Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object
- DateTime::diff() - Returns the difference between two DateTime objects

DateTime::setTimezone
DateTime::__wakeup
DateTime
PHP Manual