[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Best way to calculate total hours between two text times?

Posted on 2012-03-30
6
Medium Priority
?
332 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 400 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 81

Accepted Solution

by:
byundt earned 1600 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 400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

649 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