10
I need to calculate the working time on a call. For this I need to do operations with date
, how do I do this in the laravel
?
Code:
public function ticketsByUserSearch(Request $request)
{
$user = new User();
$user = $user->find($request->user_id);
if (!$request->initial_date) {
$data = Ticket::where('user_id', '=', $request->user_id)->get();
} else {
$initial = $request->initial_date;
$final = $request->final_date;
$data = Ticket::where('user_id', '=', $request->user_id)
->where('created_at', '>=', $initial)
->where('created_at', '<=', $final)
->get();
$jobTime = 0;
foreach ($data as $ticket){
$jobTime = $jobTime + ($ticket->closing_date - $ticket->created_at); //preciso de ajuda aqui
}
dd($jobTime);
}
$pdf = \PDF::loadView('reports.tickets-by-user-pdf', ['data' => $data, 'user' => $user]);
return $pdf->stream();
}
What Date Operation You Need to Do ?
– novic
I need the time difference.
– Felipe Paetzold
I edited the answer, and put two examples !!!
– novic