DateTime::diff

PHP 5 >= 5.3.0, PHP 7, PHP 8
DateTime::diff - Returns the difference between two DateTime objects
Manual
Code Examples

DateTime::diff( DateTimeInterface$targetObject, [bool$absolute = false] ): public DateInterval
public DateIntervalDateTimeImmutable::diff DateTimeInterfacetargetObject boolabsolutefalse

Parameters

datetime

The date to compare to.

absolute

Should the interval be forced to be positive?

Return Values

The DateInterval object represents the difference between the two dates or false on failure.

The return value more specifically represents the interval to apply to the original object ($this or $originObject) to arrive at the $targetObject. This process is not always reversible.

Related Functions

Example of DateTime::diff

Show all examples for DateTime::diff

PHP Version:


Function DateTime::diff:

Date and Time Functions

Most used PHP functions