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);
}
doc_Drupal
2016-10-29 09:01:02
Comments
Leave a Comment

Please login to continue.