(No version information available, might be only in CVS)
date_sub — Subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object
Subtracts the specified DateInterval object from the specified DateTime object.
A date as returned by DateTime().
The amount to be subtracted. For the date use "P3D", "P3M", "P3Y" or a combination of the three e.g. "P5D2M" (D = Days, M = Months, Y = Years). 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.
No value is returned.
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('P5D5M5Y'));
echo '<br />'.$date->format("d-m-Y").' : 5Days, 5 Months, 5 Years'<
span style="color: #007700">;
date_sub($date, new DateInterval('P5YT5H'));
echo '<br />'.$date->format("d-m-Y H:i:s").' : 5 Years, 5 Hours';
?>
This function is EXPERIMENTAL. The behaviour of this function, its name, and surrounding documentation may change without notice in a future release of PHP. This function should be used at your own risk.