+ Reply to Thread
Results 1 to 8 of 8

Generate total elapsed time with DATEDIF

  1. #1
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Generate total elapsed time with DATEDIF

    Can somebody explain what is missing here? Why is the elapsed time so far off with only a change in 1 months times. I can't see what it is but it appears to be happening across 2012. Am I just overlooking something obvious?

    A1 = 9 Oct 67
    B1 = 12/31/2011
    C1 = 44 years 2 months 22

    Formula:
    Please Login or Register  to view this content.
    A2 = 9 Oct 67
    B2 = 1/1/2012
    C2 = 44 years 2 months 136

    Formula:
    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 01-02-2012 at 10:30 AM.
    HTH
    Regards, Jeff

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Generate total elapsed time with DATEDIF

    I can't replicate your problem using 2003. (I don't have access to 2007 at the moment.)
    I get C2 = 44 years 2 months 23 which would seem to be correct.

    There are known bugs with DATEDIF() in 2007, but I don't recognise that one, I can't see how it can return > 31 using "md".
    This is an unsupported function so microsoft aren't going to be of much help.

    Can you post your worksheet?
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Generate total elapsed time with DATEDIF

    Here's something I found in this link Contextures Blog - Calculating Ages in Excel

    Rick Rothstein (MVP - Excel)

    February 1, 2010 at 4:10 am · Reply

    From a previous newsgroup posting of mine...

    You might want to reconsider using the DATEDIF function. It is an undocumented (and, thus, probably an unsupported) Excel function which appears to be broken in XL2007 at Service Pack 2. Someone recently posted this message as part of a newsgroup question...

    **********************************************************************
    =DATEDIF(DATE(2009,6,27),DATE(2012,1,5),"md")

    In 2007, this gives me 122. This happens all the way up to the point
    where the second date is 1/26/2012 and then it hits zero at 1/27/2012.
    In 2002, however, it gives me the correct answer of 9.
    **********************************************************************

    An informal survey of fellow MVPs shows the above formula works correctly in the initial release of XL2007 and its SP1, but does not work correctly in SP2; hence, it appears to be broken at that level. The problem is that the extent of the breakage is unknown (and probably indeterminable). In addition, I would say, being an undocumented (and, thus, probably and unsupported) function, the odds of Microsoft spending the time to search down and fix whatever broke is slim. This would seem to mean that DATEDIF cannot be counted on to work correctly from XL2007 SP2 onward. And even if Microsoft did fix the problem in a subsequent Service Pack, any of your users who remained at SP2 would be subjected to incorrect result.

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Generate total elapsed time with DATEDIF

    Thanks Marcol. The UDF, ktDATEDIF worked great and I do have the XL2007 with SP2.

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

    Re: Generate total elapsed time with DATEDIF

    Quote Originally Posted by Marcol View Post
    ....This is an unsupported function....
    I'm not sure that Microsoft have ever indicated that DATEDIF is unsupported, indeed there was a "fix" in SP2 for the "ym" version of DATEDIF (which is probably what broke the "md" version!)
    Audere est facere

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Generate total elapsed time with DATEDIF

    Aye, it seems to be refered to as undocumented rather than unsupported.

    Do you know if it is "fixed" after 2007 SP2?
    I don't have acces to excel after 2007 to try myself.

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

    Re: Generate total elapsed time with DATEDIF

    I made an attempt once before to document various DATEDIF problems.

    I'll try again here.....

    First the good news. Of the 6 possible options for argument 3, i.e. "y", "m", "d", "ym", "yd" and "md", the first 4, AFAIK all work OK in all excel versions since 2000 at least [or they work as intended, some may argue with the results]

    DATEDIF with 3rd argument "md", though, produces negative results (-1 or -2 in some cases), e.g. this formula

    =DATEDIF(DATE(1996,8,31),DATE(1998,3,1),"md")

    gives me the result -2 in 2003, 2007 and 2010. It seems to me that for those two dates you should get the result "1 year, 6 months, 1 day", i.e. result for "md" should be 1 not -2

    In Excel 2007 2 new errors crop up - the problem that Jeff reports here and that Rick Rothstein comments on, whereby "md" result is higher than would normally be expected (you wouldn't expect any result > 30 IMO)....and also a problem with "yd", whereby this formula:

    =DATEDIF(DATE(2002,1,19),DATE(2004,1,14),"yd")

    gives me a result of 473 (again, you wouldn't expect a result > 365 for "yd")

    This latter problem was fixed in SP2, I believe, or it was according to MS - the only comment in the documentation for SP2 is - The DATEDIF function returns the wrong result when the option (third) parameter is "yd."

    In Excel 2010, at least for me, these latter problems don't seem to exist, although I still get the negative numbers with "md".

    An alternative formula approach, given that the only problematic part of Jeff's formula is the 3rd DATEDIF function

    =DATEDIF(A1,B1,"y")&" years "&DATEDIF(A1,B1,"ym")&" months "&B1-MIN(DATE(YEAR(B1),MONTH(B1)-(DAY(B1)< DAY(A1))+{1,0},DAY(A1)*{0,1}))

    ...or shorter with EDATE.....

    =DATEDIF(A1,B1,"y")&" years "&DATEDIF(A1,B1,"ym")&" months "&B1-EDATE(A1,DATEDIF(A1,B1,"m"))
    Last edited by daddylonglegs; 01-03-2012 at 06:02 PM.

  8. #8
    Registered User
    Join Date
    04-01-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Generate total elapsed time with DATEDIF

    Thanks a lot! After a day wondering what is wrong with my formula, I red there is a bug in Excel 2007, but all solutions seem to be too complicated. My idea was basically like yours but I had several steps and it didn’t come to my mind to use EDATE function! Your solution is elegant and I like it best.

    My finding is that the bug isn’t fix in Excel 2007 SP3, I have wrong results for both "yd" and "md"!

    Fortunately you help me to get round this and save me a lot of time working on this problem!

    Many thanks to you again!

    Nina

+ 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