Get the farthest date from the instance (second-precision).

@param \Carbon\Carbon|\DateTimeInterface|mixed $date1
@param \Carbon\Carbon|\DateTimeInterface|mixed $date2

@return static|CarbonInterface
508581
public function farthest($date1, $date2)
    {
        return $this->diffInRealMicroseconds($date1) > $this->diffInRealMicroseconds($date2) ? $date1 : $date2;
    }
874346
protected function getValidDateObject($date)
    {
        if (empty($date)) {
            return null;
        }
        if (is_string($date)) {
            return new Carbon($date);
        }

        return $date;
    }
637915
static public function daysBetweenDates(string $date1, string $date2):? int
    {
        // If input dates have datetime 'Y-m-d X' format, take only the date part
        list($d1) = array_pad(explode(' ', $date1), 1, 0);
        list($d2) = array_pad(explode(' ', $date2), 1, 0);

        if (!self::checkDate($d1) || !self::checkDate($d2)) {
            return null;
        }

        if (!($dates = self::splitDates($d1, $d2))) {
            return null;
        }

        return (count($dates) - 1);
    }
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);
		}
	}
241900
public static function diffDays(\DateTime $dateTime1, \DateTime $dateTime2): int
    {
        $diff = $dateTime1->diff($dateTime2);

        return (int)$diff->format('%a');
    }
427166
public function getNextInvalidTimeAfter(\DateTime $date)
    {
        $difference = 1;

        $lastDate = clone $date;

        // IMPROVE THIS! The following is a BAD solution to this problem. Performance will be very bad here, depending on the cron expression. It is, however A solution.

        //keep getting the next included time until it's farther than one second
        // apart. At that point, lastDate is the last valid fire time. We return
        // the second immediately following it.
        while ($difference == 1) {
            try {
                $newDate = $this->getCronExp()->getNextRunDate($lastDate);
            } catch (\RuntimeException $e) {
                break;
            }

            $difference = ((int) $newDate->format('U')) - ((int) $lastDate->format('U'));

            if ($difference == 1) {
                $lastDate = $newDate;
            }
        }

        $lastDate->add(new \DateInterval('PT1S'));

        return $lastDate;
    }
459779
public static long subMonths(final Date date1, final Date date2) {

    Calendar calendar1 = buildCalendar(date1);
    int monthOfDate1 = calendar1.get(Calendar.MONTH);
    int yearOfDate1 = calendar1.get(Calendar.YEAR);
    Calendar calendar2 = buildCalendar(date2);
    int monthOfDate2 = calendar2.get(Calendar.MONTH);
    int yearOfDate2 = calendar2.get(Calendar.YEAR);
    int subMonth = Math.abs(monthOfDate1 - monthOfDate2);
    int subYear = Math.abs(yearOfDate1 - yearOfDate2);
    return subYear * 12 + subMonth;
  }
1291129
public static function getPatientsDateRange($date1, $date2, $wardId = 0) {
		$entityManager = ( object ) DoctrineBootstrap::getEntityManager ();
		$params = array (
				'from' => $date1,
				'to' => $date2,
				'oddzialId' => $wardId 
		);
		$q = $entityManager->createQuery ( 'select p FROM Hospitalplugin\Entities\Patient p WHERE p.dataKategoryzacji BETWEEN :from AND :to and p.oddzialId = :oddzialId ORDER BY p.name' )->setParameters ( $params )->setFirstResult ( 0 )->setMaxResults ( 1000 );
		$patients = $q->getResult ();
		return $patients;
	}
731372
private static function _utcZeroDateTime($date){

		$date = static::_nullValue($date);

		if($date === null){

			return $date;
		}

		$UTC = new DateTimeZone('UTC');
		$Date = new DateTime($date, $UTC);
		$Date->setTimezone($UTC);

		return $Date;
	}
574008
public function closest($date1, $date2)
    {
        return $this->diffInSeconds($date1) < $this->diffInSeconds($date2) ? $date1 : $date2;
    }
585969
public static boolean isSameDay(final Date date1, final Date date2) {
        final Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date1);
        final Calendar cal2 = Calendar.getInstance();
        cal2.setTime(date2);

        return cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.DATE) == cal2.get(Calendar.DATE);
    }
995520
public function checkAfter($date, $earliest)
    {
        try {
            return $this->toTimestamp($date) > $this->toTimestamp($earliest);
        } catch (InvalidArgumentException $e) {
            return false;
        }
    }
652848
public function closest(Date $dt1, Date $dt2)
    {
        return $this->diffInSeconds($dt1) < $this->diffInSeconds($dt2) ? $dt1 : $dt2;
    }
694165
public static long subSeconds(final Date date1, final Date date2) {

    return subTime(date1, date2, DatePeriod.SECOND);
  }
990727
public function secondTo(int $second): Date
    {
        return $this->createDateWithNewTime(
                $this->originalDate->hours(),
                $this->originalDate->minutes(),
                $second
        );
    }
647761
public static function compareTimeWithoutDate($date1, $date2)
    {
        $date1 = DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-01 ' . $date1->format('H:i:s'));
        $date2 = DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-01 ' . $date2->format('H:i:s'));
        if ($date1 == $date2) {
            return 0;
        }
        if ($date1 < $date2) {
            return -1;
        }

        return 1;
    }
273103
public static function date2sql($date)
    {
        $dt = new Datetime();
        
        return ($dt->set_date($date)) ? $dt->toSql() : false;
    }