You can use diffForHumans to do that.
$time->diffForHumans()
Example this
$time = Carbon\Carbon::now();
echo $time->diffForHumans();
Would give you something like this
1 second ago
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm trying to display the duration from a timestamp field. I want to display the duration as:
I tried the following, but this returns always 0 hours.
public function getDisplayHumanDurationAttribute()
{
$time = Carbon::createFromFormat('Y-m-d H:i:s', $this->duration);
return $time->diffInHours($this->duration) . Str::plural(' hour', $time->diffInHours($this->duration));
}
I'm not even sure if this is the best way to store that duration value in the database. But i thought i could use this in the future when i might have situations where i need to put starts_at and ends_at and then calculate the difference. But for now it's just one timestamp field with the duration in hours or minutes.
public function getDisplayHumanDurationAttribute()
{
return Carbon::parse($this->attributes['field_name'])->diffForHumans(null, true);
}
Please or to participate in this conversation.