+ Reply to Thread
Results 1 to 10 of 10

Calculate difference in dates

  1. #1
    Registered User
    Join Date
    05-07-2009
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Calculate difference in dates

    I need to calculate the amount of time between two dates, and show it in the number of hours and minutes. My dates are formatted to show the time in Zulu time. So 1406 = 2:06PM.

    Here is what I have:
    A1 = 6/4/08 1406Z
    B1 = 6/5/08 0402Z

    For this example, the formula should return a result of 13 hours and 58 minutes. With the result, there is no need to desingate Zulu time with a 'Z'. But I need the result in a format that will allow me to calculate an average for all my data.

    Thanks!
    Last edited by papaexcel; 07-27-2009 at 02:48 PM.

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Calculate difference in dates

    a2-a1 gives 13:56 (note not 13:58)
    but to use time in calculations you need to convert it to decimal
    =((A2-A1)*1440)/60= 13.93333333

    to convert any decimal time after calculation back to hours minutes
    =TEXT(E1/24, "[hh]:mm") where E1 is your decimal time
    Last edited by martindwilson; 07-27-2009 at 10:52 AM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Calculate difference in dates

    Try this formula in C1

    =REPLACE(LEFT(B1,LEN(B1)-1),LEN(B1)-2,0,":")-REPLACE(LEFT(A1,LEN(A1)-1),LEN(A1)-2,0,":")

    Custom format C1 as [h]:mm

  4. #4
    Registered User
    Join Date
    05-07-2009
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Calculate difference in dates

    @martindwilson - Your formula returns #VALUE error. The error occurs when subtracting A1 from A2.

    @daddylonglegs - your formula seems to ignore the dates. It calculates the time correctly, but doesn't factor in the fact the A1's date may be many days prior to B1's date.

  5. #5
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,003

    Re: Calculate difference in dates

    Try this,

    C2
    Please Login or Register  to view this content.
    Yo can also see attached.
    Hope this helps,
    windknife
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    05-07-2009
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Calculate difference in dates

    @windknife - looks like your formula works great. Thanks.

    My only problem now is how to average that number. I have over 2000 rows of data just like the example and I need to create an average of all the differences that I calculate.

  7. #7
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Calculate difference in dates

    First format the column with Windknife's formula to custom [h]:mm. Then to his formula, add +0 to the end of it. That forces the string back into a numeric value. Then you can average values. Does that work for you?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Calculate difference in dates

    sorry mate its you data thats not right then, it cant be real times but must be text
    Attached Files Attached Files

  9. #9
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Calculate difference in dates

    Quote Originally Posted by papaexcel View Post
    @daddylonglegs - your formula seems to ignore the dates. It calculates the time correctly, but doesn't factor in the fact the A1's date may be many days prior to B1's date.
    Should work fine I think, you probably didn't format as [h]:mm as advised.

    If you use my formula, as suggested above then you can use a simple AVERAGE function to average the time differences, see attached
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    05-07-2009
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Calculate difference in dates

    @daddylonglegs - You are exactly correct sir. I failed to properly format. I kept formatting as h:mm instead of [h]:mm.

    Thanks a ton!
    Last edited by papaexcel; 07-27-2009 at 02:47 PM.

+ 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