Solved

Best way to calculate total hours between two text times?

Posted on 2012-03-30
6
325 Views
Last Modified: 2012-03-30
Hello,

I have two time fields. One being the beginning time and other being the ending time

Both times are in 24 hour format and in text format

Eg:

Beginning            Ending
10:22                     15:38

I want to know what is the best way in calculating the time in-between in hours?

eg: a 330 minutes difference would be noted as 5.5 hours, etc

Thank you for your help!
0
Comment
Question by:Shanan212
6 Comments
 
LVL 17

Expert Comment

by:Anuroopsundd
ID: 37788289
0
 
LVL 81

Expert Comment

by:byundt
ID: 37788309
If you use text that looks like numbers in an arithmetic formula, it is converted into a real number. So you could calculate the hours difference as:
=24*MOD(B2-A2,1)

The business with MOD allows you to span midnight.

The multiplication by 24 is because times are stored as fractions of a day, so 12:00 noon is 0.5
0
 
LVL 27

Assisted Solution

by:Glenn Ray
Glenn Ray earned 100 total points
ID: 37788311
If the two text values are in cells A2 (beginning) and B2 (ending), then insert the following formula in cell C2:
=TIMEVALUE(B2)-TIMEVALUE(A2)

You then need to format that cell using "h:mm" to convert the value into hours and minutes.
Right-click on the cell, click Format Cells, select "Custom" from the menu on left, enter "h:mm" in the Type box (do not use quotes.

-Glenn
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 81

Accepted Solution

by:
byundt earned 400 total points
ID: 37788319
If you want to display a blank until both times have been entered, you might use:
=IF(COUNTA(A2:B2)<2,"",24*MOD(B2-A2,1))

COUNTA returns the number of cells containing text or numbers.
0
 
LVL 27

Assisted Solution

by:Glenn Ray
Glenn Ray earned 100 total points
ID: 37788327
Noting byundt's point about crossing midnight:

If that is a possibility, then my original formula should be changed to the following:
=IF(TIMEVALUE(B3)-TIMEVALUE(A3)<0,TIMEVALUE(B3)+1-TIMEVALUE(A3),TIMEVALUE(B3)-TIMEVALUE(A3))

-Glenn
0
 
LVL 13

Author Closing Comment

by:Shanan212
ID: 37788357
Thank you!<br /><br />byundt's solution provides 1.78 hours rather than 1:47 (1hr 47 mins) that Glen was able to provide.<br /><br />I require 1.78 hours to find salary.<br /><br />Regardless, valuable lessons from Glen as well!<br /><br />Thank you all!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now