Thursday 26 September 2019

database - Excel Formula to Calculate Duration of Time Based on a String of Text Such As 9:00am — 12:30pm

I'm trying to develop an Excel formula that would calculate the actual time duration for a string of a time range of the following format: 1:00am – 3:00am


According to this article it seems it should be as simple as subtracting the two times. For example, to get the hours, minutes, and seconds between two times (4:55:00), the article says to do the following:


=TEXT(B2-A2,"h:mm:ss")

Here's about how far I got:


=TEXT(RIGHT(B2,SEARCH(" – ",B2))-LEFT(B2,SEARCH(" – ",B2)),"h:mm:ss")

I wonder if the problem might be that my string of text has no "date" component in addition to the time. Is the only solution to being able to do the subtraction operation to "fudge" a date into the strings? Or is there another alternate approach, other than simply breaking down the hour and minute components individually and calculating the duration that way? I'd also like to compensate for any potential pm-to-am spans of time, such as 9:00pm — 12:00am if at all possible.

No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...