+ Reply to Thread
Results 1 to 6 of 6

subtract 2 24 hour times as string and return the number of minutes

  1. #1
    Registered User
    Join Date
    05-17-2012
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    11

    subtract 2 24 hour times as string and return the number of minutes

    If anyone can help that would be appreciated.

    How do i subtract two times that are entered in 24 hour time format but are strings and return the difference in minutes

    For example

    StopTime = 21:15
    RestartTime = 22:00

    Therefore MachineDownTime in minutes = RestartTime - StopTime

    Any help would be appreciated

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,919

    Re: subtract 2 24 hour times as string and return the number of minutes

    What exactly is in the cells? Is it the entire string "StopTime = 21:15"?
    If you have:
    A1: StopTime = 21:15
    A2: RestartTime = 22:00
    Try:
    B1: =Right(A2,5)-Right(A1,5), format B1 as Time.
    Ben Van Johnson

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2411
    Posts
    26,693

    Re: subtract 2 24 hour times as string and return the number of minutes

    If they are entered in 24-hour time format, are you sure they are strings in Excel? Are the cells formatted as "Text"?

    This formula works, even though the times are formatted as text strings. Excel will convert for you. I'm assuming that the stop time is in A1 and the restart time is in A2. This also handles the case where the interval crosses midnight:

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2411
    Posts
    26,693

    Re: subtract 2 24 hour times as string and return the number of minutes

    On review of protonLeah's response, that's good point--I assumed that only the time was in the cell but if you have the whole string then you will have to use RIGHT as shown.

    Also, I didn't explain this in my response but the result for time subtraction is in units of days, so you have to multiply by 24*60 (or 1440) to get minutes. If you want to display the result in 00:00 format then you don't need to multiply but if you just need the number of minutes you do.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: subtract 2 24 hour times as string and return the number of minutes

    =(A2+0)-(A1+0) will return the time difference if A1 and A2 are either strings or excel times.

    Since this will be in Excel serial time, you could use either

    =TEXT((A2+0)-(A1+0), "[m]")+0
    or
    =((A2+0)-(A1+0))*24*60

    to return the number of minutes in that interval.
    Last edited by mikerickson; 11-22-2012 at 12:32 AM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Registered User
    Join Date
    05-17-2012
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: subtract 2 24 hour times as string and return the number of minutes

    Thanks for everyones help this provides me with what i require.

+ 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