summarize time interval

Hi. I have a "hours" field in my database, containig time user works in a task My column is: TextColumn::make('hours') ->label('Duración') ->time() ->summarize(Sum::make()->label('Tiempo trabajado')) ->sortable(), But "total" is not calculated ok. how can I calculate correct time sum?
No description
No description
Solution:
just use the original hours column is enough
No description
Jump to solution
23 Replies
PabloZagni
PabloZagniOP17mo ago
Anyone?
Saade
Saade17mo ago
Use a custom summarizer with a custom query, something like:
SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `hours` ) ) ) AS totalhours
SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `hours` ) ) ) AS totalhours
PabloZagni
PabloZagniOP17mo ago
https://filamentphp.com/docs/3.x/tables/summaries Custom summaries are "using" a query... don't know how to implement it
No description
Saade
Saade17mo ago
$query->raw()?
PabloZagni
PabloZagniOP17mo ago
but, how to apply to filtered records?
PabloZagni
PabloZagniOP17mo ago
I've done it for a basic table, but don't know how to do it in filament
No description
PabloZagni
PabloZagniOP17mo ago
Anyone?
toeknee
toeknee17mo ago
using $query->sum() ?
awsqed
awsqed17mo ago
$query->sum(DB::raw('TIME_TO_SEC(hours)'))
$query->sum(DB::raw('TIME_TO_SEC(hours)'))
then combine with your logic to convert from seconds to H:i:s
PabloZagni
PabloZagniOP17mo ago
I had to create a column "seconds" = TIME_TO_SEC(hours) but when I summarize, it give me sum(seconds), I need to formar it H:i:s now, theres no formatUsing func to Summarize
toeknee
toeknee17mo ago
Can you provide the code you are using?
PabloZagni
PabloZagniOP17mo ago
No description
PabloZagni
PabloZagniOP17mo ago
No description
toeknee
toeknee17mo ago
so as above see: https://filamentphp.com/docs/3.x/tables/summaries#custom-summaries you can format the display for you. As you are summing duration this is a time which needs diving by 60 etc.
PabloZagni
PabloZagniOP17mo ago
This doesn't work
No description
Solution
awsqed
awsqed17mo ago
just use the original hours column is enough
No description
PabloZagni
PabloZagniOP17mo ago
Thanks for your answer!! Is this Filament 2 ? I'm trying to implement and I get errors Sum <> Summarizer Builder <> QueryBuilder...
awsqed
awsqed17mo ago
its filament 3 QueryBuilder = Illuminate\Database\Query\Builder
PabloZagni
PabloZagniOP17mo ago
Done!!!!
No description
PabloZagni
PabloZagniOP17mo ago
No description
PabloZagni
PabloZagniOP17mo ago
Thanks!!! I coulnd't find the right sintax!
awsqed
awsqed17mo ago
youre welcome

Did you find this page helpful?