How to sum N number of time (HH:MM Format)?

后端 未结 5 1303
独厮守ぢ
独厮守ぢ 2020-11-27 21:43

I am using the following sample code to calculate sum of two different time values. Now I want to get the sum of N number of time values.

// numbers for test         


        
5条回答
  •  长情又很酷
    2020-11-27 22:17

    Laravel Framework (PHP language)

         $chores = ChoresTime::where('family_id', $family->id)->get();
            $total = [];
            foreach ($chores as $key => $value) {
                $total[] = $value->time;
            }
          $total = CalculateTime($chores);
          return response()->json([
              'status' => 1, 
              'message' => 'Total Time', 
              'data' => [], 
              'total' => $total 
          ], ok());
    

    Answer:

    {
        "status": 1,
        "message": "Family Total Chores Time",
        "data": [],
        "total": "14:22"
    }
    

提交回复
热议问题