+ Reply to Thread
Results 1 to 11 of 11

Difference in hours between two date/time columns

  1. #1
    Registered User
    Join Date
    05-09-2016
    Location
    Baton Rouge, LA
    MS-Off Ver
    Office 2013
    Posts
    7

    Smile Difference in hours between two date/time columns

    I would like to get the difference in hours between B2 & C2 in D2. What formula would I use for this? I am new to excel and trying to learn more
    B2 and C2 are formatted 01/03/2016 0858

    Thanks!!

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Difference in hours between two date/time columns

    Excel wont see 0858 as time, you will have to format the cells as Date/Time so it shows like this 08:58. Then format D2 as number and use this formula in D2....
    Please Login or Register  to view this content.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Registered User
    Join Date
    05-09-2016
    Location
    Baton Rouge, LA
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Difference in hours between two date/time columns

    Thank you. The formatting must be wrong. I'm getting #VALUE and have B and C formatted as m/d/yyy [h]:mm and column D formatted as [h]:mm. Any idea why I'm not getting my value?

  4. #4
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Difference in hours between two date/time columns

    B2 and C2 are formatted 01/03/2016 0858
    Is that really the value in the cells, 0858 for the time, it's not 08:58 ??

    That would explain the #Value! error, because 0858 isn't really a valid time, so the cell as a whole is just a TEXT string, not a Date+Time.

    Can you attach a sample book?

  5. #5
    Registered User
    Join Date
    05-09-2016
    Location
    Baton Rouge, LA
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Difference in hours between two date/time columns

    Attached Sample book.
    Attached Files Attached Files

  6. #6
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Difference in hours between two date/time columns

    Yep, you have 2 problems with the source data.
    1. your times are written as 0858 (no colon to sepate the hours:minutes) So it's not a valid time.
    2. Column A has leading spaces

    So this can be resolved by adjusting the source date/time values like this
    C2: =TRIM(REPLACE(A2,LEN(A2)-1,0,":"))
    D2: =TRIM(REPLACE(B2,LEN(B2)-1,0,":"))

    Then use
    =(D2-C2)*24

  7. #7
    Registered User
    Join Date
    05-09-2016
    Location
    Baton Rouge, LA
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Difference in hours between two date/time columns

    Thats seemed to work but then when I use =(D2-C2)*24, some of the values are incorrect. I might have a time (for example in row 4) that is showing 22 hours and 24 min difference when it is really less than an hour. I'm attaching the new sheet
    named Sample Book. Any idea of what that could be?
    Attached Files Attached Files

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Difference in hours between two date/time columns

    The formula is returning the value as Number of Hours, not a TIME.
    But formatting the cell as a TIME makes it look strange.

    Do you want the values to be returned as an actual TIME value ? If yes, remove the *24, and format the cell as TIME
    Or do you want the values returned as number of hours in decimal value ? Keep the *24, but format the cell as NUMBER with 2 decimals.

  9. #9
    Registered User
    Join Date
    05-09-2016
    Location
    Baton Rouge, LA
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Difference in hours between two date/time columns

    I want the number of hours. But some of them are not accurate and some are. (like in Row 4 of the sample that I attached)

  10. #10
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Difference in hours between two date/time columns

    Format the cells with the formula as NUMBER, not as Time.

  11. #11
    Registered User
    Join Date
    05-11-2016
    Location
    Tennessee
    MS-Off Ver
    2013-2016
    Posts
    6

    Re: Difference in hours between two date/time columns

    I added a sheet of Jonmo1's solution, and also added to your formula to blank the cell if Row D is blank so that you can have the formula run down without always dragging it around.
    Attached Files Attached Files

+ 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. Return difference in days, hours, minutes between two date and time ranges.
    By craig amolsch in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-03-2013, 06:21 PM
  2. Replies: 1
    Last Post: 09-13-2012, 05:50 AM
  3. Replies: 0
    Last Post: 09-13-2012, 05:28 AM
  4. Replies: 8
    Last Post: 05-28-2011, 03:27 AM
  5. Replies: 3
    Last Post: 12-23-2010, 04:46 PM
  6. Time Difference in hours between two date time stamps
    By Cipher in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-17-2010, 10:24 AM
  7. Query: Difference between date/time columns
    By uneek78 in forum Access Tables & Databases
    Replies: 5
    Last Post: 11-05-2009, 02:32 PM
  8. Hours difference between 2 Date & Time stamps
    By bondi26 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-21-2007, 10:24 PM

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