+ Reply to Thread
Results 1 to 7 of 7

Subtracting Times in Excel with a nuance

  1. #1
    Registered User
    Join Date
    05-31-2012
    Location
    PA
    MS-Off Ver
    Excel 2007
    Posts
    53

    Subtracting Times in Excel with a nuance

    I am trying to subtract times in excel and currently they are pulling in from another spreadsheet in which there are no spaces between the time and the AM or PM for example, instead of 3:50 AM it is 3:50AM. So the formula =text(B2-A2,"h:mm") is not working and I think that is because of the space. Is there another way to calculate this? I also would like it to show up as 5.82 hours say instead of giving me a time back.

    Any help is greatly appreciated. Thanks!
    MR

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,418

    Re: Subtracting Times in Excel with a nuance

    If you can't change the source data then you can do this with your formula:

    =(SUBSTITUTE(SUBSTITUTE(B2,"AM",""),"PM","") - SUBSTITUTE(SUBSTITUTE(A2,"AM",""),"PM",""))*24

    Hope this helps.

    Pete

  3. #3
    Registered User
    Join Date
    05-31-2012
    Location
    PA
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Subtracting Times in Excel with a nuance

    Thank you!!! this is close! super helpful. I'm showing 9:10AM and 3:00PM. it should equal 5.82 hours. after using your formula I'm getting -6.17 which is great because it's an actual number and not showing an error, however, I know it's not the right answer. I must be missing something else.

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,418

    Re: Subtracting Times in Excel with a nuance

    Ah, no. I need to add 0.5 on if it is PM at the end. Let me try a few things out in a worksheet, and I'll get back to you.

    Pete

  5. #5
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,418

    Re: Subtracting Times in Excel with a nuance

    Okay, you can use this formula instead:

    =(LEFT(B2,LEN(B2)-2)+IF(RIGHT(B2,2)="PM",0.5,0) - (LEFT(A2,LEN(A2)-2)+IF(RIGHT(A2,2)="PM",0.5,0)))*24

    Hope this helps.

    Pete

  6. #6
    Registered User
    Join Date
    05-31-2012
    Location
    PA
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Subtracting Times in Excel with a nuance

    This is fantastic!!! and complicated!!! haha! Thank you so much!! You are a life saver!

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,418

    Re: Subtracting Times in Excel with a nuance

    Well, times are stored by Excel as fractions of a 24-hour day, so 12:00 noon will be stored as 0.5, 6:00 am as 0.25, and so on. The LEFT bit of the formula just extracts the numerical part of B2 (or A2), but as I indicated in Post #4 I also need to add in 12 hours (or 0.5) if there is a PM after the time, so that is what the two IF functions do. So, the formula is basically (B2 - A2)*24, where B2 and A2 are suitably adjusted and as you want the result in hours rather than in Excel time formula we need to multiply the result by 24.

    If that takes care of your original question, please take a moment to select Thread Tools from the menu above your first post and mark this thread as SOLVED.

    Also, you might like to know that you can directly thank those who have helped you by clicking on the small "star" icon located in the lower left corner of a post that you have found to be helpful (not just in this thread - for any post that has helped you). This also adds to the reputation of the poster (the small green bars in the poster's profile).

    Pete

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Subtracting two times
    By nicolelschramartin in forum Excel General
    Replies: 2
    Last Post: 12-09-2012, 07:46 PM
  2. Pivot Table Nuance assistance
    By razor0323 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-22-2011, 05:12 PM
  3. Subtracting Times
    By Knawl in forum Excel General
    Replies: 4
    Last Post: 11-02-2010, 03:49 AM
  4. Subtracting times
    By acuratlmike in forum Excel General
    Replies: 8
    Last Post: 10-06-2009, 02:09 PM
  5. [SOLVED] Subtracting times.
    By in forum Tips and Tutorials
    Replies: 5
    Last Post: 03-10-2006, 12:34 PM
  6. Subtracting times
    By gaftalik in forum Excel General
    Replies: 3
    Last Post: 11-02-2005, 02:45 PM
  7. Subtracting Times
    By bhalchandra2000 in forum Tips and Tutorials
    Replies: 1
    Last Post: 08-23-2005, 12:08 PM
  8. [SOLVED] Subtracting times
    By robin_gould_durban@hotmail.com in forum Excel General
    Replies: 1
    Last Post: 01-12-2005, 06:06 AM

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