datetime.sub(3) php man page | unix.com

Man Page: datetime.sub

Operating Environment: php

Section: 3

DATETIME.SUB(3) 							 1							   DATETIME.SUB(3)

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

       Object oriented style

SYNOPSIS
public DateTime DateTime::sub (DateInterval $interval)
DESCRIPTION
Procedural style DateTime date_sub (DateTime $object, DateInterval $interval) Subtracts the specified DateInterval object from the specified DateTime object.
PARAMETERS
o $object -Procedural style only: A DateTime object returned by date_create(3). The function modifies this object. o $interval - A DateInterval object
RETURN VALUES
Returns the DateTime object for method chaining or FALSE on failure.
EXAMPLES
Example #1 DateTime.sub(3) example Object oriented style <?php $date = new DateTime('2000-01-20'); $date->sub(new DateInterval('P10D')); echo $date->format('Y-m-d') . " "; ?> Procedural style <?php $date = date_create('2000-01-20'); date_sub($date, date_interval_create_from_date_string('10 days')); echo date_format($date, 'Y-m-d'); ?> The above examples will output: 2000-01-10 Example #2 Further DateTime.sub(3) examples <?php $date = new DateTime('2000-01-20'); $date->sub(new DateInterval('PT10H30S')); echo $date->format('Y-m-d H:i:s') . " "; $date = new DateTime('2000-01-20'); $date->sub(new DateInterval('P7Y5M4DT4H3M2S')); echo $date->format('Y-m-d H:i:s') . " "; ?> The above example will output: 2000-01-19 13:59:30 1992-08-15 19:56:58 Example #3 Beware when subtracting months <?php $date = new DateTime('2001-04-30'); $interval = new DateInterval('P1M'); $date->sub($interval); echo $date->format('Y-m-d') . " "; $date->sub($interval); echo $date->format('Y-m-d') . " "; ?> The above example will output: 2001-03-30 2001-03-02
NOTES
DateTime.modify(3) is an alternative when using PHP 5.2.
SEE ALSO
DateTime.add(3), DateTime.diff(3), DateTime.modify(3). PHP Documentation Group DATETIME.SUB(3)
Related Man Pages
datetime.settimestamp(3) - php
datetime.__construct(3) - php
datetime(3) - php
datefmt_format_object(3) - php
dateinterval.format(3) - php
Similar Topics in the Unix Linux Community
sed help
Help needed with date
Shell script (KSH) to list ONLY the ID of male employees whose last loging time was during the last
How to find the date format
Dmesg with date possible?