John Davidson

php - Summary minutes with hours in Laravel

0 comments
Message:


I am beginner in Laravel. I make my project in Laravel 5.8.
I have minutes and hours in DB.


I have this code:


$workedHours = WorkingTime::where('case_id', $request->id)->sum('hours_worked');
$workedMinutes = WorkingTime::where('case_id', $request->id)->sum('minutes_worked');

Example result:


$workedHours = 438;
$workedMinutes = 483;

I need to add hours over minutes and display the total. For example, 44:12 (44 hours and 12 minutes).


How can i make this?



My Answer:
>case_id)->sum('hours');
$workedMinutes = WorkingTime::where('case_id', $request->case_id)->sum('minutes');

$totalHours = $workedHours + floor($workedMinutes / 60);
$totalMinutes = $workedMinutes % 60;

return "Total time worked: " . $totalHours . " hours and " . $totalMinutes . " minutes";

Rate this post

5 of 5 based on 7940 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us