briannesbitt/Carbon · error · UnknownUnitException
$unit
Error message
$unit
What it means
Error "$unit" thrown in briannesbitt/Carbon.
Source
Thrown at src/Carbon/Traits/Difference.php:112
}
/**
* @param Unit|string $unit microsecond, millisecond, second, minute,
* hour, day, week, month, quarter, year,
* century, millennium
* @param \Carbon\CarbonInterface|\DateTimeInterface|string|null $date
* @param bool $absolute Get the absolute of the difference
* @param bool $utc Always convert dates to UTC before comparing (if not set, it will do it only if timezones are different)
*
* @return float
*/
public function diffInUnit(Unit|string $unit, $date = null, bool $absolute = false, bool $utc = false): float
{
$unit = static::pluralUnit($unit instanceof Unit ? $unit->value : rtrim($unit, 'z'));
$method = 'diffIn'.$unit;
if (!method_exists($this, $method)) {
throw new UnknownUnitException($unit);
}
return $this->$method($date, $absolute, $utc);
}
/**
* Get the difference in years
*
* @param \Carbon\CarbonInterface|\DateTimeInterface|string|null $date
* @param bool $absolute Get the absolute of the difference
* @param bool $utc Always convert dates to UTC before comparing (if not set, it will do it only if timezones are different)
*
* @return float
*/
public function diffInYears($date = null, bool $absolute = false, bool $utc = false): float
{
$start = $this;
$end = $this->resolveCarbon($date);View on GitHub (pinned to b13f05955d)
When it happens
Trigger: Thrown at src/Carbon/Traits/Difference.php:112 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of briannesbitt/Carbon@b13f05955d (2026-08-17).
Data as JSON: /api/errors/e2435c0038cc02d1.
Report an issue: GitHub.