phpeveryday Posted November 7, 2013 Share Posted November 7, 2013 Hi All, I'm trying to find a way to calculate the total time in seconds of when 3 different times intersect each other. e.g. Start Time End Time Duration 2013-10-08 08:29:52 2013-10-08 08:32:46 00:02:54 2013-10-08 08:31:57 2013-10-08 08:32:46 00:00:49 2013-10-08 08:32:06 2013-10-08 08:36:28 00:04:22 From my calculation it will 85 seconds of overlapping time. Can anyone assist? Quote Link to comment Share on other sites More sharing options...
phpeveryday Posted November 7, 2013 Author Share Posted November 7, 2013 Start Time End Time Duration 2013-10-08 08:29:52 2013-10-08 08:32:46 00:02:54 2013-10-08 08:31:57 2013-10-08 08:32:46 00:00:49 2013-10-08 08:32:06 2013-10-08 08:36:28 00:04:22 Hopefully the above displays better. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted November 7, 2013 Share Posted November 7, 2013 Example 1: <?php $start_TimeStr="2013-10-08 08:29:52"; $end_TimeStr = "2013-10-08 08:32:46"; $Duration = strtotime($end_TimeStr) - strtotime($start_TimeStr); echo $Duration; // 174 sec Quote Link to comment Share on other sites More sharing options...
phpeveryday Posted November 7, 2013 Author Share Posted November 7, 2013 Hi jazzman1, Thanks for your response. I was more looking at the subset or intersection of the the three rows where the End Time of all the rows do not exceed the End Time of the first row. Actually my initial calculation of 85 seconds is incorrect. I believe it should be 40 seconds. Here is my logic:- From the first row the duration is 00:02:54 or 174 seconds. The second row the Start and End time falls within the first Start and End and the duration is 49 seconds and is the total subset time used at this time. The third row starts within the second row but ends after the second row so the duration will be a difference of 2013-10-08 08:32:06 and 2013-10-08 08:32:46 which is 40 seconds. I hope I am a bit clearer. Quote Link to comment Share on other sites More sharing options...
litebearer Posted November 7, 2013 Share Posted November 7, 2013 Perhaps... new_start_time would be LATEST start time of the three new_end_time would be EARlIEST end time of the three those two would be the common intersection/duration of the three (would apply to more or less time sequences) Quote Link to comment Share on other sites More sharing options...
phpeveryday Posted November 7, 2013 Author Share Posted November 7, 2013 Hi litebearer, I believe that may be the solution. I will try it. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.