+ Reply to Thread
Results 1 to 8 of 8

Two time values in a single cell, how to return difference?

  1. #1
    Registered User
    Join Date
    04-13-2012
    Location
    Vantaa
    MS-Off Ver
    Excel 2010
    Posts
    1

    Two time values in a single cell, how to return difference?

    Hi guys

    I have a single cell in which a time window (in lack of a better word!) has been exported in text format, like this:

    10:15-15:00

    What I need as a result into another cell is the difference between those times in hours and minutes, in this case four hours and forty-five minutes (4:45)

    The formula should work with times between 0:00-23:59, also with times that pass midnight (ex. 23:00-5:00 = 6.0 hours)

    I wasn't able to figure out a combo that works. How could I accomplish this?

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Two time values in a single cell, how to return difference?

    Not the neatest formula in the world, but with your string in cell A2 this should work:

    =((TIMEVALUE(TRIM(LEFT(A2,FIND("-",A2)-1)))>TIMEVALUE(TRIM(MID(A2,FIND("-",A2)+1,255))))+TIMEVALUE(TRIM(MID(A2,FIND("-",A2)+1,255))))-TIMEVALUE(TRIM(LEFT(A2,FIND("-",A2)-1)))

  3. #3
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Two time values in a single cell, how to return difference?

    Try this

    =MOD(MID(A2,FIND("-",A2)+1,9)-LEFT(A2,FIND("-",A2)-1),1)

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Two time values in a single cell, how to return difference?

    That gives me a value error when it tries to subtract one string from another, Bob, but this works:

    =MOD(TIMEVALUE(MID(A2,FIND("-",A2)+1,255))-TIMEVALUE(LEFT(A2,FIND("-",A2)+1)),1)

  5. #5
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Two time values in a single cell, how to return difference?

    Really, it works fine for me.

  6. #6
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Two time values in a single cell, how to return difference?

    Actually, yours gives me an error, it should be

    =MOD(TIMEVALUE(MID(A3,FIND("-",A3)+1,255))-TIMEVALUE(LEFT(A3,FIND("-",A3)-1)),1)

  7. #7
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Two time values in a single cell, how to return difference?

    Wow, that's weird. You're right, it should be -1 rather than +1, but both work fine for me.

    Oh well, I've had too many glasses of wine to worry about it - let's call it a draw

  8. #8
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Two time values in a single cell, how to return difference?

    Got it - the difference is in if there are spaces before and after the dash - if there are then both versions of my formula work fine but yours doesn't, if there are not then your formula and the corrected version of mine work, but the uncorrected version doesn't.

    As we haven't heard back from the OP the point is probably moot.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1