<?php $time_start = [ 0 => '22:00:00', 1 => '03:00:00', ]; $time_end = [ 0 => '02:00:00', 1 => '08:00:00', ]; $logs = [ 0 => '2019-07-09 22:00:00', 1 => '2019-07-10 02:00:00', 2 => '2019-07-10 03:00:00', 3 => '2019-07-10 08:00:00', ]; $time = []; $diff = 0; for ($j = 0; $j < count($logs); $j = $j + 2) { $attendance_start = date("Y-m-d", strtotime($logs[$j])); $attendance_end = date("Y-m-d", strtotime($logs[$j + 1])); for ($i = 0; $i < count($time_start); $i++) { $time_starts = date('Y-m-d H:i:s', strtotime("$attendance_start " . $time_start[$i] . "")); $time_ends = date('Y-m-d H:i:s', strtotime("$attendance_end " . $time_end[$i] . "")); if ($logs[$j] >= $time_starts && $logs[$j + 1] <= $time_ends) { array_push($time, $logs[$j], $logs[$j + 1]); $diff += (round((strtotime($logs[$j + 1]) - strtotime($logs[$j])) / 3600, 1)); break; } } } echo $diff . " Hours";die;
You have javascript disabled. You will not be able to edit any code.