php - Non-overlapping minutes per day -


i have been cracking head trying resolve problem.

i need know how many minutes of day being worked staff member alone in shop.

here data daynumber = 0 (monday):

table data - example

for day, staff member staffid = 32 alone 11:00 11:05 in shop.

what have far, adding starting times, i'm thinking is, if have way of knowing staff member alone, can calculate time between index , next.

for($i=0; $i<count($results); $i++){     if(isset($results[$i+1])){         if($results[$i]->starttime < $results[$i+1]->starttime)             $start = strtotime($results[$i]->starttime);             $end = strtotime($results[$i+1]->endtime);             $minutes +=  idate('i', $end - $start);         }     } } 

any thoughts?

update 1: still no luck;

    for($i=0; $i<count($results); $i++){         if(isset($results[$i+1])){             $startdate1 = strtotime($results[$i]->starttime);             $enddate1 = strtotime($results[$i]->endtime);             $startdate2 = strtotime($results[$i+1]->starttime);             $enddate2 = strtotime($results[$i+1]->endtime);              if(($startdate1 <=  $enddate2) && ($enddate1 >= $startdate2)){                 $startdate1 = idate('i', $startdate1);                 $enddate1 = idate('i', $enddate1);                 $startdate2 = idate('i', $startdate2);                 $enddate2 = idate('i', $enddate2);                  $a = abs($enddate1 - $startdate1);                 $b= abs($enddate1 - $startdate2);                 $c = abs($enddate2 - $startdate2);                 $d = abs($enddate2 - $startdate1);                  $minutes += min([$a,$b,$c,$d]);             }         }     } 

what doing wrong?

here's 1 idea, using utility table - in case table of integers 0-9. utility tables frowned on some, them because mean less typing. can replace table string of unions.

this days. might modify later show how filter specific day.

select * ints; +---+ | | +---+ | 0 | | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | +---+  select sec_to_time((i4.i*1000+i3.i*100+i2.i*10+i1.i)*60) n    ints i1    join ints i2    join ints i3    join ints i4    join       ( select daynumber             , min(starttime) starttime             , max(case when endtime < starttime sec_to_time(time_to_sec('24:00:00')+time_to_sec(endtime)) else endtime end) endtime           my_table          group             daynumber      ) x      on sec_to_time((i4.i*1000+i3.i*100+i2.i*10+i1.i)*60) between x.starttime , x.endtime   join my_table y     on sec_to_time((i4.i*1000+i3.i*100+i2.i*10+i1.i)*60) between y.starttime , case when y.endtime < y.starttime sec_to_time(time_to_sec('24:00:00')+time_to_sec(y.endtime)) else y.endtime end  group     n having count(*) = 1;  number of lone minutes equal number of rows in result. 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -