downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DateTime::__wakeup> <DateTime::setTimezone
Last updated: Fri, 30 Oct 2009

view this page in

DateTime::sub

(PHP 5 >= 5.3.0)

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

Beschreibung

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

Subtracts the specified DateInterval object from the specified DateTime object.

Parameter-Liste

object

Nur bei prozeduralem Aufruf: Ein von date_create() zurückgegebens DateTime Objekt.

interval

A DateInterval object

Rückgabewerte

Returns the modified DateTime.

Beispiele

Beispiel #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';

?>

Siehe auch

  • 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



add a note add a note User Contributed Notes
DateTime::sub
There are no user contributed notes for this page.

DateTime::__wakeup> <DateTime::setTimezone
Last updated: Fri, 30 Oct 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites