[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
Medium Priority
332 Views
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

0
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

LVL 17

Expert Comment

ID: 37788289
0

LVL 81

Expert Comment

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

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

LVL 81

Accepted Solution

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

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

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

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.
###### Suggested Courses
Course of the Month14 days, 20 hours left to enroll