×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

time diff function

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!

RE: time diff function

Are you trying to calculate 11 am divided by 6 pm? I don't think that has any meaning.

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

Assuming that you will get the timeformat because that you import from some other program that will only give this format i made a small macro that will do the job BUT ONLY FOR WHOLE HOURS!

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

And one small item more: The function will not be correct if your start and finish is before and after midnight.

Best Regards

Morten

RE: time diff function

Format the cells like stated by DaveViking
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources