DateTimeInterface::diffDateTimeImmutable::diffDateTime::diffdate_diffReturns the difference between two DateTime objects DescriptionObject-oriented style
public DateInterval DateTimeInterface::diff(DateTimeInterface
$targetObject , bool $absolute = false )public DateInterval DateTimeImmutable::diff(DateTimeInterface
$targetObject , bool $absolute = false )public DateInterval DateTime::diff(DateTimeInterface
$targetObject , bool $absolute = false )Procedural style DateInterval date_diff(DateTimeInterface
$baseObject , DateTimeInterface $targetObject , bool $absolute = false )Returns the difference between two DateTimeInterface objects. Parameters
Return ValuesThe DateInterval object represents the difference between the two dates.
The
The return value more specifically represents the clock-time interval to
apply to the original object (
The method is aware of DST changeovers, and hence can return an interval of
ExamplesExample #1 DateTimeImmutable::diff example Object-oriented style
Procedural style
The above examples will output: +2 days Example #2 DateTimeInterface::diff during DST changeover
The above example will output: 24:30:00 (Full days: 0) Example #3 DateTimeInterface::diff range
The value that the method returns is the exact amount of time to get from
The above example will output: Full days: 364 Example #4 DateTime object comparison
The above example will output: bool(false) bool(true) bool(false) See Also
|