Solved

Best way to calculate total hours between two text times?

Posted on 2012-03-30
6
327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

737 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