function DateTimePlus::diff
Same name in other branches
- 9 core/lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\DateTimePlus::diff()
- 8.9.x core/lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\DateTimePlus::diff()
- 11.x core/lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\DateTimePlus::diff()
Returns the difference between two DateTimePlus objects.
Parameters
\Drupal\Component\Datetime\DateTimePlus|\DateTime $datetime2: The date to compare to.
bool $absolute: Should the interval be forced to be positive?
Return value
\DateInterval A DateInterval object representing the difference between the two dates.
Throws
\BadMethodCallException If the input isn't a DateTime or DateTimePlus object.
File
-
core/
lib/ Drupal/ Component/ Datetime/ DateTimePlus.php, line 379
Class
- DateTimePlus
- Wraps DateTime().
Namespace
Drupal\Component\DatetimeCode
public function diff($datetime2, $absolute = FALSE) {
if ($datetime2 instanceof DateTimePlus) {
$datetime2 = $datetime2->dateTimeObject;
}
if (!$datetime2 instanceof \DateTime) {
throw new \BadMethodCallException(sprintf('Method %s expects parameter 1 to be a \\DateTime or \\Drupal\\Component\\Datetime\\DateTimePlus object', __METHOD__));
}
return $this->dateTimeObject
->diff($datetime2, $absolute);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.