Support the ongoing development of Laravel.io →
posted 9 years ago
Views Packages
Last updated 1 year 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 1 year ago.
0

Thanks atrakeur that was right on the money!

Last updated 1 year 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.