Hello Im just a beginner programmer but Im now building an app which gets the total hours of work.
Here I have a time_start array which the threshold for the customer to in and same as out for time_end
The logs here is where the person checks in.
$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',
];
So I'm trying to get the sum of their hours in night shift which has different date.
Im trying to get it in:
foreach( $logs as $check_time ){
$attendance_date_time = date("Y-m-d",strtotime($check_time));
$time_starts = date('Y-m-d H:i:s', strtotime("$attendance_date_time $time_start"));
$time_ends = date('Y-m-d H:i:s', strtotime("$attendance_date_time $time_end"));
if ( $check_time >= $time_starts && $check_time <= $time_ends )
{
$time[] = $check_time;
}else{
$time = null
}
}
Supposedly I will get all logs because it is between time_start and time_end and store it to $time
And summing the time i get.
Since I'm new at php is their any easiest idea to get the total work hours? Cuz I get a null because the time_end it gets was the date of check_in.
2019-09-09 22:00to2019-09-10 02:00equals to4hours.2019-07-10 03:00:00to2019-07-10 08:00:00equals to5hours