Obter um intervalo entre datas completas do formato 'd/m/Y H:i:s'.

@param \DateTime|string $data1
@param \DateTime|string $data2
@return false|\DateInterval
779174
public function intervaloEntreDatasHoraBr($data1, $data2)
    {
        $data1 = $this->converterParaDateTime($data1, $this->FORMATO_DATA_HORA_BR);
        $data2 = $this->converterParaDateTime($data2, $this->FORMATO_DATA_HORA_BR);

        if (!$data1 || !$data2) {
            return false;
        }

        return date_diff($data1, $data2);
    }
447564
private function compareDate(DateTime $value1, DateTime $value2, $operator)
    {
        $diff = $value1->format('U') - $value2->format('U');
        switch ($operator) {
            case FieldExpression::EQUALS:
                return $diff === 0;
            case FieldExpression::NOT_EQUALS:
                return $diff !== 0;

            case FieldExpression::GT:
                return $diff > 0;

            case FieldExpression::LT:
                return $diff < 0;
        }

        $errMsg = 'unknown field operator';
        throw new InvalidArgumentException($errMsg);
    }
69497
public static function compare($date1, $date2, $type = 'date') {
		if ($type == 'date') {
			return date('Y-m-d', strtotime($date1)) === date('Y-m-d', strtotime($date2));
		} else if ($type == 'datetime' || $type == 'time') {
			return date('Y-m-d H:i:s', strtotime($date1)) === date('Y-m-d H:i:s', strtotime($date2));
		} else {
			return strtotime($date1) == strtotime($date2);
		}
	}
22931
public static function compare($date1, $date2): int
    {
        $d1 = static::create($date1);
        $d2 = static::create($date2);

        return ($d1 > $d2) ? static::DATETIME_GREATER : (($d1 < $d2) ? static::DATETIME_LESS : static::DATETIME_EQUAL);
    }
1349875
public static function datetime2sql($datetime)
    {
        $datetime = trim($datetime);
        if (empty($datetime)) {
            return false;
        }
        
        // Test si déjà au format aaaa-mm-jj
        if (preg_match('#\d{4}-\d{2}-\d{2} \d{2}:\d{2}#', $datetime)) {
            return $datetime;
        }
        
        return preg_replace('#(\d{1,2})/(\d{1,2})/(\d{1,4}) (\d{1,2}):(\d{1,2})#', "$3-$2-$1 $4:$5:00.0", $datetime);
    }
139283
public function age($date1, $date2 = null)
    {
        $formatter = new AgeFormatter();

        return $formatter->formatDate($date1, $date2);
    }
638025
public static function niceTimeDiff($d1, $d2, $limitPeriods = 2)
    {
        if (!is_int($d1)) {
            $d1 = self::strtotime($d1);
        }
        if (!is_int($d2)) {
            $d2 = self::strtotime($d2);
        }
        if (empty($d1) or empty($d2)) {
            return false;
        }
        $max = max($d1, $d2);
        $min = min($d1, $d2);
        $diff = $max - $min;

        return self::niceDuration($diff, $limitPeriods);
    }
27747
public function formatInterval(\DateInterval $dateInterval): string
    {
        $format = 'P';

        if (0 < $dateInterval->y) {
            $format .= $dateInterval->y.'Y';
        }

        if (0 < $dateInterval->m) {
            $format .= $dateInterval->m.'M';
        }

        if (0 < $dateInterval->d) {
            $format .= $dateInterval->d.'D';
        }

        if (0 < $dateInterval->h || 0 < $dateInterval->i || 0 < $dateInterval->s) {
            $format .= 'T';
        }

        if (0 < $dateInterval->h) {
            $format .= $dateInterval->h.'H';
        }

        if (0 < $dateInterval->i) {
            $format .= $dateInterval->i.'M';
        }

        if (0 < $dateInterval->s) {
            $format .= $dateInterval->s.'S';
        }

        return $format;
    }
250190
public static function compare($date1, $date2, $operator = null)
    {
        $date1 = $date1 instanceof \DateTimeInterface ? $date1 : new \DateTime($date1);
        $date2 = $date2 instanceof \DateTimeInterface ? $date2 : new \DateTime($date2);

        if ($operator === null) {
            if ($date1 == $date2) {
                return 0;
            }

            return (int) ($date1 < $date2);
        }

        switch ((string) $operator) {
            case '=':
                return $date1 == $date2;
            case '!=':
                return $date1 != $date2;
            case '>':
            case 'gt':
                return $date1 > $date2;
            case '>=':
            case 'gte':
                return $date1 >= $date2;
            case '<':
            case 'lt':
                return $date1 < $date2;
            case '<=':
            case 'lte':
                return $date1 <= $date2;
        }

        throw new \InvalidArgumentException('Invalid operator: ' . $operator);
    }
842805
public function toDateInterval() : \DateInterval
    {
        return \DateInterval::createFromDateString(\sprintf(
            '%d years %d months %d days',
            $this->years,
            $this->months,
            $this->days
        ));
    }
708980
public function differenceDateTime($dateTime = null) {
        if (!empty($dateTime)) {
            $this->setDateTime($dateTime, true);
        }
        $this->dateTimeInterval = $interval = $this->dateTime->diff($this->dateTimeDiff);
        return $interval;
    }
209814
public static function intervalToTime(DateInterval $interval)
    {
        $time = null;

        if (!is_null($interval)) {
            $format = property_exists(get_class($interval), 'u') ? '%H:%I:%S.%U' : '%H:%I:%S';
            $time = $interval->format($format);
        }

        return $time;
    }
1101729
public static function toSecondsUsingDays(\DateInterval $interval)
    {
        $seconds = (string) $interval->s;

        if ($interval->i) {
            $seconds = bcadd($seconds, bcmul($interval->i, self::SECONDS_MINUTE));
        }

        if ($interval->h) {
            $seconds = bcadd($seconds, bcmul($interval->h, self::SECONDS_HOUR));
        }

        if ((false !== $interval->days) && (0 <= $interval->days)) {
            $seconds = bcadd($seconds, bcmul($interval->days, self::SECONDS_DAY));
        } else {
            throw new InvalidArgumentException(
                'The "days" property is not set.'
            );
        }

        return $seconds;
    }
969828
private function getSeconds(DateInterval $interval)
    {
        $date = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
        $date2 = $date->add($interval);
        return $date2->getTimestamp() - $date->getTimestamp();
    }
767138
public function overlaps(\DateTime $start, \DateTime $end) {
    $overlaps = FALSE;

    if ($this->dateIsEarlier($start) &&
      ($this->dateIsInRange($end) || $this->dateIsLater($end))) {
      $overlaps = TRUE;
    } elseif ($this->dateIsInRange($start) &&
      ($this->dateIsInRange($end) || $this->dateIsLater($end))) {
      $overlaps = TRUE;
    }

    return $overlaps;
  }
740587
public static function splitDate($dateTime, $type = 'int')
    {
        $t  = explode(' ', $dateTime);
        $t1 = explode('-', $t[0]);
        $t2 = explode(':', $t[1]);
        if ($type == 'int') {
            $x['date']   = (int)$t1[2];
            $x['month']  = (int)$t1[1];
            $x['year']   = (int)$t1[0];
            $x['hour']   = (int)$t2[0];
            $x['minute'] = (int)$t2[1];
            $x['second'] = (int)$t2[2];
        } else { // string
            $x['date']   = $t1[2];
            $x['month']  = $t1[1];
            $x['year']   = $t1[0];
            $x['hour']   = $t2[0];
            $x['minute'] = $t2[1];
            $x['second'] = $t2[2];
        }

        return $x;
    }
390899
public function compararDataHoraFormatoBr($data1, $simbolo, $data2)
    {
        $data1 = $this->converterParaDateTime($data1, $this->FORMATO_DATA_HORA_BR);
        $data2 = $this->converterParaDateTime($data2, $this->FORMATO_DATA_HORA_BR);

        if (!$data1 || !$data2) {
            return false;
        }

        return $this->compararDatasFormatado($data1, $simbolo, $data2);
    }