Search code examples
excelfunctionformula

Issue with DATEDIF function


DATEDIF function giving different values as shown in the snapshot. Why this?

enter image description here


Solution

  • First of all, you should avoid passing D2 directly to DATEDIF formula. DATEDIF requires first 2 arguments as a date. You pass 0 and D2 (C2-B2). Since lowest possible date in excel is 01-Jan-1900 and it is = 1, your arguments are 0 = 0-Jan-1900 (non existing date) and 546 = 29-Jun-1900. You would get more errors in calculation if your dates would include leap year (1900 is not leap year)

    Also consider looking at Microsoft as it states there are issues with "md" argument (see "Known issues").

    So correct formula would be:

    =DATEDIF(B2,C2,"y")&" years "&DATEDIF(B2,C2,"ym")&" months "&DATEDIF(B2,C2,"md")&" days"
    

    Result: enter image description here