DateTime::diffDateTimeImmutable::diffDateTimeInterface::diffdate_diffReturns the difference between two DateTime objects
&reftitle.description;
&style.oop;publicDateIntervalDateTime::diffDateTimeInterfacetargetObjectboolabsolute&false;publicDateIntervalDateTimeImmutable::diffDateTimeInterfacetargetObjectboolabsolute&false;publicDateIntervalDateTimeInterface::diffDateTimeInterfacetargetObjectboolabsolute&false;&style.procedural;DateIntervaldate_diffDateTimeInterfacebaseObjectDateTimeInterfacetargetObjectboolabsolute&false;
Returns the difference between two DateTimeInterface
objects.
&reftitle.parameters;
datetime
The date to compare to.
absolute
Should the interval be forced to be positive?
&reftitle.returnvalues;
The DateInterval object represents the
difference between the two dates&return.falseforfailure;.
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.
&reftitle.examples;
DateTime::diff example&style.oop;
diff($target);
echo $interval->format('%R%a days');
?>
]]>
&style.procedural;
format('%R%a days');
?>
]]>
&examples.outputs;
DateTime object comparison
As of PHP 5.2.2, DateTime objects can be compared using
comparison operators.
$date2);
?>
]]>
&example.outputs;
&reftitle.seealso;
DateInterval::formatDateTime::addDateTime::sub