Closed Thread
Results 1 to 10 of 10

Calculating hh:mm between two times that span midnight

  1. #1
    Registered User
    Join Date
    02-07-2005
    Location
    Albany, Oregon
    Posts
    9

    Calculating hh:mm between two times that span midnight

    I have searched the forum, but admit to having given up when all the similar-sounding problems/solutions I looked at did not seem to apply to my issue.

    I have two times I want to calculate the difference from: A1 is the time a person went to sleep (ex. 10:43 PM); A2 is when the person woke up (ex. 6:00 AM). Since these times span from one day to the next, I am finding myself unable to create a formula that properly returns the result (A3) of 7:15.

    I have formatted A1 and A2 as "Time, 1:30 PM."
    I have formatted A3 as "Custom, hh:mm."

    What is the correct formula I need to obtain the result I desire? Can I do this in a way that assumes the hours slept does *not* exceed 24 hours [i.e.: without having to specify dates in addition to the times]?

    Thanks for your help in this.

    --John

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: Calculating hh:mm between two times that span midnight

    try =MOD(A2-A1, 1)

  3. #3
    Registered User
    Join Date
    02-07-2005
    Location
    Albany, Oregon
    Posts
    9

    Smile Re: Calculating hh:mm between two times that span midnight

    Wow. That's just so freakin' simple.

    Thank you!

    --John

  4. #4
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Calculating hh:mm between two times that span midnight

    Please Login or Register  to view this content.
    where A5 is the earlier time


    click on the * Add Reputation if this was useful or entertaining.

  5. #5
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Calculating hh:mm between two times that span midnight

    Quote Originally Posted by tony h View Post
    Please Login or Register  to view this content.
    where A5 is the earlier time
    Or =B5-A5+(B5<A5)

  6. #6
    Registered User
    Join Date
    11-10-2010
    Location
    Victoria, Australia
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Calculating hh:mm between two times that span midnight

    or simply format the time cells as Custom, [h]:mm
    (This is the 24 hour clock format but recognising that something can run for longer than 24 hours or past the midnight date change)
    then add 24:00 to the later time
    then subtract the earlier time

    e.g.
    [A1]22:43
    [B1]30:00
    [C1]=B1-A1
    [Answer] 7:17

    Easy peasy, lemon squeezy
    Last edited by Data Cruncher; 11-10-2010 at 05:28 AM. Reason: Typo and no sign-off

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Calculating hh:mm between two times that span midnight

    @DataCruncher, thanks, welcome to the board.

    FWIW, adding the additional 24 hours is illustrated in both tonyh/arthurbr's examples - neither of which necessitate source values be altered from their original values (the adjustment forms part of the calculation itself).

  8. #8
    Registered User
    Join Date
    05-27-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Calculating hh:mm between two times that span midnight

    the code of formula doesnt quite work with my example; im getting 13:33:00 for my answer which is totally incorrect. please help

    11:37 01:10

    thanks

  9. #9
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: Calculating hh:mm between two times that span midnight

    From the rules:

    2. Don't post a question in the thread of another member -- start your own. If you feel it's particularly relevant, provide a link to the other thread.

  10. #10
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Calculating hh:mm between two times that span midnight

    Nana D you have already received a warning for hijacking threads less than 30 min ago. Please abide by forum rules. Thread closed


    Your post does not comply with Rule 7 of our Forum RULES. Please do not ignore Moderators' or Administrators' requests - note that this includes requests by senior members as well, if you are unclear about their request or instruction then send a private message to them asking for help. Do not post a reply to a thread where a moderator has requested an action that has not been complied with e.g Title change or Code tags...etc

Closed 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