Excel formula or VBA Identifying gaps in overlapping dates and times - excel

I am attempting to find any gaps calculated in minutes between a start and stop date/time range. Essentially time when there are no appointments in the schedule, this is a 24hr service and I am looking for "dead" time when there isn't a customer in the office.
Currently I was attempting to use the =SUMPRODUCT((A2<B$2:B$19)*(B2>A$2:A$19))>1 to find overlaps and the issue I am running into is if there are any overlap in start or stop it disqualifies and does not truly identify the space between appointments just if that appointment is double booked at all.

Here is a new version of the Gap and Island solution to this problem, using Excel 365 functionality:
=LET(start,A2:A19,
end,B2:B19,
row,SEQUENCE(ROWS(start)),
maxSoFar,SCAN(0,row,LAMBDA(a,c,IF(c=1,INDEX(start,1),IF(INDEX(end,c-1)>a,INDEX(end,c-1),a)))),
SUM(IF(start>maxSoFar,start-maxSoFar,0)))
The algorithm is very simple:
- Sort data by start time if necessary, then for each pair of times:
- Record the latest finish time so far (maxSoFar) (not including the present appointment)
- If the start time (start) is greater than maxSoFar, add start-maxSoFar to the total.
The first time interval is a special case - initialise maxSoFar to the first start time.
It can be seen that there are only two gaps in the appointments, from 4:15 to 7:31 (3 hours 16 minutes) and from 11:48 to 14:17 (3 hours 29 minutes) totalling 5 hours 45 minutes.
Why didn't I just use Max to make the code shorter? I don't know:
=LET(start,A2:A19,
end,B2:B19,
row,SEQUENCE(ROWS(start)),
maxSoFar,SCAN(0,row,LAMBDA(a,c,IF(c=1,INDEX(start,1),MAX(INDEX(end,c-1),a)))),
SUM(IF(start>maxSoFar,start-maxSoFar,0)))

To find the gaps between appointments in a schedule, you can try using the following formula:
=SUM(B2:B19)-SUMPRODUCT((A2<B$2:B$19)*(B2>A$2:A$19))
You can then convert the duration to minutes by multiplying the result by 1440 (the number of minutes in a day).
=1440*(SUM(B2:B19)-SUMPRODUCT((A2<B$2:B$19)*(B2>A$2:A$19)))

Related

I produce 365 items in one hour and 4000 in 10.95 hour how to set when it will complet by time

Let's say i logged in today 9:00 AM and end up 5:00 PM i have to produce 4000 items i know it will exceed the time because my software will stop working at 5 PM so tomorrow when i start working again what would be date and time of completion work
What i did
bring working hour =SUM(B2-A2)
total complete work=ROUND(D2/C2, 2)
If i understood correctly you can use the simple difference of times and correct formatting for the time cells to get the remaining hours
The Formula in cell C5 is simple =C1-C3
The formatting applied to the cells is as below
10.95 hours is equal to 10 hours and 57 (95% of 60) minutes
You can write 10:57:00 instead of 10.95
To convert the time to again a number you can divide the time by 0.041666667 and set the format to general

Calculate minutes in specific period

I have a spreadsheet which has employee working times, listed as Sat-In and Sat-Out for a specific date. The employee shift spans several ours and each "In-Out" period is recorded as a separate line which means the time between the Sat-Out and the next Sat-In means the employee is on a break. I also calculate the time, in minutes of each "sitting" period.
What I can't seem to figure out is how to add a formula which takes the data and further refines it in this manner:
1. I have a core period of 1030-1530, as an example, which is the busy time and requires the maximum employee coverage. The shifts of employees generally spans this core, but in some cases their shift may start or end in the core.
2. I want to calculate how many minutes the employee worked within the core only. I can obviously do this manually using the data, but a formula would be preferred, if possible.
3. As an example, if a person sat-in at 1445 and sat-out at 1545, the core time calculation would be 45 minutes (1445-1530).
I've attached a snapshot of the data to help my explanation.
FYI - the information is pulled from a database as JSON data and converted to excel. I'm not very familiar with JavaScript, but if someone knows a way to do it programatically, I'm willing to give it a try and learn.
Thanks!
![excel]: https://photos.app.goo.gl/dRSTE72CXNa18RzP8
In below example I've used: =MAX(0,MIN($O$2,H2)-MAX($O$1,G2)), and formatted like [mm].
In Excel, units are days, so if you want to calculate the amount of minutes between two timestamps, you need to subtract both and multiply the differencee by 24*60 (being the amount of minutes in one day).
E.g. You start working at 09:07 (cell B2), and finish at 18:07 (cell B3), having a 45-minutes break. Then the time you worked in minutes, is:
=(B3-B2)*24*60-45
Make sure the cell formatting is correct (general), you'll get : 495.

Calculate difference between two dates to calculate hours and minutes

I would like to get the difference in hours and minutes between two dates with the numbers after the colon in the number of minutes for a SharePoint List on SharePoint 2013. For example:
1st Date: 1/5/2019 1:00 AM
2nd Date: 1/6/2019 2:15 AM
Total: 25:15
=INT((([Date Time Test]-Created)*1440)/60) this gives total of hours. If I remove the 60, that gives total number of minutes or I have tried this: =INT((([Date Time Test]-Created)*24) which also gives the number of hours.
The way I see it, you will need three calculated columns:
one to calculate hours
one to calculate minutes
last one displays the hours & minutes
The big disadvantage of this approach is that all three columns will have to be included in the relevant views.
Second approach (depending on your SP version) - have a workflow calculate hours & minutes and output the result to a single line of text column.
Lastly you can also consider column formatting, depending on SP version again.
You could try to CONCATENATE the hours and minutes, for example:
=CONCATENATE(INT((([SDate]-Created)*1440)/60),":",INT(([SDate]-Created)*1440))

Excel units of time conversion

I need to change a value of time from days:hours:minutes, into either hours with a decimal or minutes. My data comes up as 001:05:46 for example. I am having trouble with the leading zeros confusing excel. Any help would be great!
Assuming that your value to parse is formatted in DDD:HH:MM like 001:05:46... There are a lot of ways to do this but here's a simple one. To convert into hours we need to take the days times 24 hours per day, add the hours, and add the minutes times 1 hour per 60 minutes:
=LEFT(A1,3)*24+MID(A1,5,2)+RIGHT(A1,2)/60
To get this value in terms of minutes we multiply by 60 minutes per hour. A possible modification of the original formula to reach this point would be:
=LEFT(A1,3)*24*60+MID(A1,5,2)*60+RIGHT(A1,2)

How to get the difference in minutes between two dates in Microsoft Excel?

I am doing some work in Excel and am running into a bit of a problem. The instruments I am working with save the date and the time of the measurements and I can read this data into Excel with the following format:
A B
1 Date: Time:
2 12/11/12 2:36:25
3 12/12/12 1:46:14
What I am looking to do is find the difference in the two date/time stamps in mins so that I can create a decay curve from the data. So In Excel, I am looking to Make this (if the number of mins in this example is wrong I just calculated it by hand quickly):
A B C
1 Date: Time: Time Elapsed (Minutes)
2 12/11/12 2:36:25 -
3 12/12/12 1:46:14 1436.82
I Have looked around for a bit and found several methods for the difference in time but they always assume that the dates are the same. I exaggerated the time between my measurements some but that roll over of days is what is causing me grief. Any suggestions or hints as to how to go about this would be great. Even If I could find the difference between the date and times in hrs or days in a decimal format, I could just multiple by a constant to get my answer. Please note, I do have experience with programming and Excel but please explain in details. I sometimes get lost in steps.
time and date are both stored as numerical, decimal values (floating point actually). Dates are the whole numbers and time is the decimal part (1/24 = 1 hour, 1/24*1/60 is one minute etc...)
Date-time difference is calculated as:
date2-date1
time2-time1
which will give you the answer in days, now multiply by 24 (hours in day) and then by 60 (minutes in hour) and you are there:
time elapsed = ((date2-date1) + (time2-time1)) * 24 * 60
or
C3 = ((A3-A2)+(B3-B2))*24*60
To add a bit more perspective, Excel stores date and times as serial numbers.
Here is a Reference material to read up.
I would suggest you to use the following:
Combine date to it's time and then do the difference. So it will not cause you any issues of next day or anything.
Please refer to the image with calculations. You may leave your total minutes cell as general or number format.
MS EXCEL Article: Calculate the difference between two times
Example as per this article
Neat way to do this is:
=MOD(end-start,1)*24
where start and end are formatted as "09:00" and "17:00"
Midnight shift
If start and end time are on the same day the MOD function does not affect anything. If the end time crosses midnight, and the end is earlier then start (say you start 23PM and finish 1AM, so result is 2 hours), the MOD function flips the sign of the difference.
Note that this formula calculates the difference between two times (actually two dates) as decimal value. If you want to see the result as time, display the result as time (ctrl+shift+2).
https://exceljet.net/formula/time-difference-in-hours-as-decimal-value
get n day between two dates, by using days360 function =days360(dateA,dateB)
find minute with this formula using timeA as reference =(timeB-$timeA+n*"24:00")*1440
voila you get minutes between two time and dates
I think =TEXT(<cellA> - <cellB>; "[h]:mm:ss") is a more concise answer. This way, you can have your column as a datetime.

Resources