Calculate difference between two dates to calculate hours and minutes - sharepoint

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))

Related

Excel formula or VBA Identifying gaps in overlapping dates and times

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)))

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 should durations of time be displayed in a spreadsheet?

I'm creating a report which display duration of time (in hours) between two points in time.
e.g.
Duration between 10:00 to 13:30 equals 3 hrs 30 minutes
This information is being saved into a spreadsheet (excel) in one "duration" column, titled "Duration (hrs)". The column needs to be sortable to allow sorting by longest duration, etc.
Should this be displayed as 3.5 or 3.30 using a numerical column format? Or as 03:30 using a time format? Is there a standard for this or purely down to preference?
Appreciate your thoughts!
Thanks,
Andy
Note also that if you use "hh:mm" for your time format, that will just give you max 24, so even if it goes over several days, you won't see more than 24 hours. If you want the TOTAL number of hours, use "[hh]:mm" to see e.g. 45:32
I think it's probably just down to preference - either method should work and be sortable
For a time format you can just subtract, e.g.
=B2-A2
or for decimal just multiply by 24
=(B2-A2)*24
Personally I think that time durations should be kept in time format.....

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.

What is wrong with this calculated field for total hours between two times in SharePoint 2007?

I am attempting to get the total hours between two times in a SharePoint 2007 list. Right now I have the formula as...
=INT(([Column2]-[Column1])*24)
...which I have looked up and says that it is the correct formula to do this. But, what I get is a weird date like "2/18/1900 12:00 AM" instead of what it should be: 26.
Another formula I tried was...
=TEXT([Column2]-[Column1],"h")
...but, this will only get the difference in hours and not count the days (if they are more than one apart).
Both of the columns are Date & Time columns. So, what am I doing wrong?
My take is that you set the output format of the calculated column to be Date and Time, while it should be of type number.
In a calculated column, the number of hours between two times is:
=TEXT([Column2]-[Column1],"h")
Providing that the difference is less than 24 hours. Otherwise, you'll need to look at getting the days difference and doing a multi-step calculation involving the number of days between the dates * 24 + the calc above.

Resources