public function DateTimePlus::diff

public DateTimePlus::diff($datetime2, $absolute = FALSE)

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 329

Class

DateTimePlus
Wraps DateTime().

Namespace

Drupal\Component\Datetime

Code

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);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Datetime!DateTimePlus.php/function/DateTimePlus::diff/8.1.x