+ Reply to Thread
Results 1 to 7 of 7

DATEDIF and Custom format producing different results

  1. #1
    Registered User
    Join Date
    02-17-2010
    Location
    Wirral
    MS-Off Ver
    Excel 2007
    Posts
    26

    DATEDIF and Custom format producing different results

    I have a spreadsheet with lots of event dates on and also people's dates of birth. I have used formulas to work out the age in days of each person at each event. So far, so good.

    I then added a simple 'LARGE' formula to find the oldest person at any event. This gave me the answer 12977.

    I used Custom Format to convert this result from days into years, months and days and got the answer 35y 7m 12d.

    But using DateDif to check the result gives 35y 6m 12d and I can't understand why there is a difference of 1 month. The DateDif result is the correct one but I can't use this to convert the value of 12977 as that could change to a different value in the future.

    Why does Custom Format give a different answer? Is there a way round the problem?
    Last edited by Wirral Wizard; 07-06-2010 at 10:59 AM.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: DATEDIF and Custom format producing different results

    what dates are you dealing with to produce the 12977 result?
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    02-17-2010
    Location
    Wirral
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: DATEDIF and Custom format producing different results

    Thanks Sweep. Dates are 4/2/62 and 16/8/97.

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

    Re: DATEDIF and Custom format producing different results

    The custom format you used is not appropriate for displaying a duration. That sort of formatting is essentially date based, so for months you will always get a figure 1 to 12, whereas for a duration you need to be in the range 0 to 11 so months always display 1 higher than expected. There's no easy way (or even a difficult way that I know) to do that with formatting

    If you want years, months and days you can do that with DATEDIF too, e.g. with DOB in A2 and event date in B2

    =DATEDIF(A2,B2,"y")&"y "&DATEDIF(A2,B2,"ym")&"m "&DATEDIF(A2,B2,"md")&"d"
    Audere est facere

  5. #5
    Registered User
    Join Date
    02-17-2010
    Location
    Wirral
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: DATEDIF and Custom format producing different results

    Thanks DLL. I did know about getting years, months and days with DATEDIF. But if I use this I can't then use a formula to identify the oldest, youngest etc. etc. (unless you know differently!). Hence the reason for using days only.

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

    Re: DATEDIF and Custom format producing different results

    Well, if you have DOBs in A2:A10 then to get the oldest person you need the smallest DOB so you could either use a separate cell with the formula

    =MIN(A2:A10) and then reference that cell in the formula (instead of A2) or you could just use that directly in the formula, e.g.

    =DATEDIF(MIN(A2:A10),B2,"y")&"y "&DATEDIF(MIN(A2:A10),B2,"ym")&"m "&DATEDIF(MIN(A2:A10),B2,"md")&"d"

    ......or do you need to get the maximum age across different events? If that's the case then you could just use your previous system to get the maximum number of days and, assuming that's in cell D2 you could use DATEDIF like this

    =DATEDIF(0,D2,"y")&"y "&DATEDIF(0,D2,"ym")&"m "&DATEDIF(0,D2,"md")&"d"

    [BTW if you only want the difference in days you don't really need DATEDIF at all, you can just subtract the DOB from the event date, i.e. =B2-A2]

  7. #7
    Registered User
    Join Date
    02-17-2010
    Location
    Wirral
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: DATEDIF and Custom format producing different results

    That last bit gave me the solution DLL, thanks very much for your help.

+ 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