dongwei1234 2015-03-17 09:03
浏览 41
已采纳

两个或多个时间间隔之间的持续时间(以PHP表示)

I have time interval as below,

1-  07:00:00 to 09:30:00 (duration 02:30:00)
2-  08:00:00 to 11:00:00 (duration 03:00:00)

But actual combined duration is 07:00:00 - 11:00:00 (Dur 04:00:00). When we are adding 2 individual duration it will give result 5:30:00..like this different combinations may happen(1-7,5-8,9-10,6-9:30) I want a logic to find actual duration without considering intersecting time intervals. If it is already answered kindly give me the path to it. Thanks in Advance. Note: It is to calculate the duration of work done from attendance data and on duty slips

  • 写回答

2条回答 默认 最新

  • dongtu4028 2015-03-17 14:04
    关注
    enter code here
    
    function compareTimes($start,$end)  
     {
     $count=count($start);
     for($i=0;$i<$count;$i++)
     {
      for($j=0;$j<$count;$j++)
      {
       if($j==$i)
       {
    
       }
       elseif($start[$j]>=$start[$i] and $start[$j]<=$end[$i]) 
       {
         if($end[$j]>=$start[$i] and $end[$j]<=$end[$i]) 
         {
           $start[$j]="0";
           $end[$j]="0";
         }  
         else
         {
            $end[$i]=$end[$j];
            $start[$j]="0";
           $end[$j]="0";
         }
       }
    
      }
     }
     $dur=0;
     $count1=count($start);
     for($i=0;$i<$count1;$i++)
     {
      $dur1=$end[$i]-$start[$i];
      $dur=$dur1+$dur;
     }
      return $dur;   
     }
    

    // EXAMPLE FOR THE PERIOD 5-6,4-8 &8-9

      $start=array("5","4","8");
    
      $end=array("6","8","9");
      $check=compareTimes($start,$end);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法