Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

datetimeimmutable.diff(3) [php man page]

DATETIMEIMMUTABLE.DIFF(3)						 1						 DATETIMEIMMUTABLE.DIFF(3)

DateTime::diff - Returns the difference between two DateTime objects

       Object oriented style

SYNOPSIS
public DateInterval DateTime::diff (DateTimeInterface $datetime2, [bool $absolute = false]) DESCRIPTION
DateInterval DateTimeImmutable::diff (DateTimeInterface $datetime2, [bool $absolute = false]) DateInterval DateTimeInterface::diff (Date- TimeInterface $datetime2, [bool $absolute = false]) Procedural style DateInterval date_diff (DateTimeInterface $datetime1, DateTimeInterface $datetime2, [bool $absolute = false]) Returns the difference between two DateTimeInterface objects. PARAMETERS
o $datetime - The date to compare to. o $absolute - Should the interval be forced to be positive? RETURN VALUES
The DateInterval object representing the difference between the two dates or FALSE on failure. EXAMPLES
Example #1 DateTimeImmutable.diff(3) example Object oriented style <?php $datetime1 = new DateTime('2009-10-11'); $datetime2 = new DateTime('2009-10-13'); $interval = $datetime1->diff($datetime2); echo $interval->format('%R%a days'); ?> Procedural style <?php $datetime1 = date_create('2009-10-11'); $datetime2 = date_create('2009-10-13'); $interval = date_diff($datetime1, $datetime2); echo $interval->format('%R%a days'); ?> The above examples will output: +2 days Example #2 DateTime object comparison Note As of PHP 5.2.2, DateTime objects can be compared using comparison operators. <?php $date1 = new DateTime("now"); $date2 = new DateTime("tomorrow"); var_dump($date1 == $date2); var_dump($date1 < $date2); var_dump($date1 > $date2); ?> The above example will output: bool(false) bool(true) bool(false) SEE ALSO
DateInterval.format(3), DateTime.add(3), DateTime.sub(3). PHP Documentation Group DATETIMEIMMUTABLE.DIFF(3)

Check Out this Related Man Page

DATETIMEIMMUTABLE(3)							 1						      DATETIMEIMMUTABLE(3)

The DateTimeImmutable class

INTRODUCTION
This class behaves the same as DateTime except it never modifies itself but returns a new object instead. CLASS SYNOPSIS
DateTimeImmutable DateTimeImmutableDateTimeInterface Methods o public DateTimeImmutable::__construct NULL ([string $time = "now"], [DateTimeZone $timezone]) o public DateTimeImmutable DateTimeImmutable::add (DateInterval $interval) o publicstatic DateTimeImmutable DateTimeImmutable::createFromFormat (string $format, string $time, [DateTimeZone $timezone]) o publicstatic DateTimeImmutable DateTimeImmutable::createFromMutable (DateTime $datetime) o publicstatic array DateTimeImmutable::getLastErrors (void ) o public DateTimeImmutable DateTimeImmutable::modify (string $modify) o publicstatic DateTimeImmutable DateTimeImmutable::__set_state (array $array) o public DateTimeImmutable DateTimeImmutable::setDate (int $year, int $month, int $day) o public DateTimeImmutable DateTimeImmutable::setISODate (int $year, int $week, [int $day = 1]) o public DateTimeImmutable DateTimeImmutable::setTime (int $hour, int $minute, [int $second]) o public DateTimeImmutable DateTimeImmutable::setTimestamp (int $unixtimestamp) o public DateTimeImmutable DateTimeImmutable::setTimezone (DateTimeZone $timezone) o public DateTimeImmutable DateTimeImmutable::sub (DateInterval $interval) o public DateInterval DateTimeImmutable::diff (DateTimeInterface $datetime2, [bool $absolute = false]) o public string DateTimeImmutable::format (string $format) o public int DateTimeImmutable::getOffset (void ) o public int DateTimeImmutable::getTimestamp (void ) o public DateTimeZone DateTimeImmutable::getTimezone (void ) o public DateTimeImmutable::__wakeup (void ) PHP Documentation Group DATETIMEIMMUTABLE(3)
Man Page