sanjayacloud
1 week ago
164
12
Laravel

Cannot get sum of the total working hours.

Posted 1 week ago by sanjayacloud

Hi Guys,

I am trying to get sum of total working hours for the user.

My code like below

@php
                                     $total_hours = array();
                                    @endphp
                                    @foreach($reports as $report)
                                        <tr>
                                            <td>{{$report->date}}</td>
                                            <td>{{$report->check_in_time}}</td>
                                            <td>{{$report->check_out_time}}</td>
                                            <td>
                                                @php
                                                    $dteStart = new DateTime($report->check_in_time);
                                                    $dteEnd   = new DateTime($report->check_out_time);
                                                    $dteDiff  = $dteStart->diff($dteEnd);
                                                @endphp
                                                {{ round($dteDiff->format("%H:%I"), 2) }}
                                            </td>
                                            <td> {{ $dteDiff->format("%H:%I") }}</td>
                                        </tr>
                                        @php
                                            $dt = $dteDiff->format("%H:%I");
                                            $total_hours[] = $dteDiff->format("%H:%I");
                                        @endphp
                                    @endforeach

And show sum of the working hours.

<p>{{ array_sum($total_hours)}}</p>

This total coming from

23:00 + 01:05 

Total should be 24:05, But my showing value is rounded value "24". can I know how to show the actual value of "24:05"?

Please sign in or create an account to participate in this conversation.