Solved

Best way to calculate total hours between two text times?

Posted on 2012-03-30
6
324 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
Comment Utility
0
 
LVL 80

Expert Comment

by:byundt
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 80

Accepted Solution

by:
byundt earned 400 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

743 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

18 Experts available now in Live!

Get 1:1 Help Now