Support the ongoing development of Laravel.io →
posted 10 years ago
Views Packages
Last updated 2 years ago.
0

Try something like

public function getDurationAttribute()
{
    return $this->end->diffForHumans($this->start);
}

Then just access it using :

$model->duration;

Beware of some edge cases (this code will fail if end is null).

Also you can use the Carbon documentation about dates comparaisons and differences:

https://github.com/briannesbitt/Carbon#api-comparison

https://github.com/briannesbitt/Carbon#difference

Last updated 2 years ago.
0

Thanks atrakeur that was right on the money!

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

netm netm Joined 2 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.