time diff function
time diff function
(OP)
Does anyone know how I can determine the number of hours between 2 different times that are entered in the below format? I want to populate another cell with the actual number of hours.
11a/6p
Thanks in advance for any suggestions!
11a/6p
Thanks in advance for any suggestions!





RE: time diff function
On the other hand, if you're trying to compute the difference between 11 am and 6 pm, as in started work at 11, ended at 6, that's seven hours, you might try this:
1. Format the cells in question, including the calculation cells as "time" cells - picking your favorite, i.e., military, etc. Or make a custom time format so 11:00 shows up as "11a" - it's easy.
2. After that, it's pretty straight-forward. The only trick is that you _have_ to enter the hours and minutes as "11:00" and not "11" or "11a" as Excel won't know what you mean.
3. I've found that using the military time format makes things easier (e.g., 6 pm = 18:00, etc.).
4. Excel will do the math properly, that is, 6 pm - 11 am = 7 hours, or 7:00. Play around with the Format > Cell capabilities, you'll find what you want.
RE: time diff function
Public Function ellapsed_time(start, finish)
If Right(start, 1) = "a" Then
start = Left(start, Len(start) - 1)
Else
start = Left(start, Len(start) - 1) + 12
End If
If Right(finish, 1) = "a" Then
finish = Left(finish, Len(finish) - 1)
Else
finish = Left(finish, Len(finish) - 1) + 12
End If
ellapsed_time = finish - start
End Function
You can copy paste from your browser and right into the EXCEL VB editor
Just call the function and the result will be the no. of hours between start and end.
Best Regards Morten
RE: time diff function
Best Regards
Morten
RE: time diff function
Lets say you have the times in C1 and B1
use the functions HOUR and MINUTE
if C1 = 21:23 and B1 = 14:24
=HOUR(C1-B1) for the difference in hours = 6
=MINUTE(C1-B1) for the difference in minutes = 59
Regards
Steven van Els
SAvanEls@cq-link.sr