+ Reply to Thread
Results 1 to 6 of 6

Odd Time result

  1. #1
    Forum Contributor
    Join Date
    06-16-2010
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    152

    Odd Time result

    Just curious about this.

    My Uncle is approaching his 100th Birthday, so I applied some formulae to work out how many days he'd been alive.

    However, taking a Microsoft Help page on calculating differences in dates, they gave the following formula

    Please Login or Register  to view this content.
    So if I put 11/7/1918 in A2 and 11/7/2018 in B2 the result is
    100 years, 0 months, 10 days

    Why the extra 10 days?
    Even if it were something to do with leap years, it would be 25 days!?!

    If I enter 30/5/1960 and 30/5/2018 respectively I get 58 years, 0 months, 29 days

    Elsewhere, I've seen DATEDIF(A2,B2,"md") used for the days portion, so I'm just curious why MS used it differently and why the discrepancies.

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

    Re: Odd Time result

    Over the years, in different versions of Excel there have sometimes been issues within the "md" version of DATEDIF (returning negative numbers in some cases), so this would just appear to be a way to avoid using DATEDIF with "md".......but it's pretty meaningless as that part references B2 date only, so it will always show the day of B2-1.

    This version will only work reliably if A2 is always the first of the month

    In the past to avoid problems with "md" I've used this formula for the days part

    =B2-EDATE(A2,DATEDIF(A2,B2,"m"))&" days"

    For example, this formula returns -2

    =DATEDIF(DATE(2017,5,31),DATE(2018,3,1),"md")

    whereas

    =DATE(2018,3,1)-EDATE(DATE(2017,5,31),DATEDIF(DATE(2017,5,31),DATE(2018,3,1),"m"))

    formatted as number, returns 1
    Last edited by daddylonglegs; 01-16-2018 at 02:40 PM.
    Audere est facere

  3. #3
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Odd Time result

    Quote Originally Posted by neil40 View Post
    so I applied some formulae to work out how many days he'd been alive.
    I am assuming you didnt actually mean what you asked for. You stated "days" alive. If thats what you actually meant its simply newer date - older date and format it as a number/general. Ex: 11/7/1918 - 11/7/2018 = x days (B2 - A2).

    If you are looking for days, months and years then it gets more complicated. Primarily leap years become a problem but there are other considerations that make this hard to do.

    As mentioned some built in functions have quirks and will in some circumstances produce odd results. DATEDIF is (or at least was) an undocumented function for a long time. As such while it is available to use I never use it as I dont expect it to function properly.

    So the question becomes are you looking for years with months/days as a remainder? or are you looking for total years, total months, total days (independent of each other)?

    I do know if you want to convert days to years you can do days * 365.25 (365 days in a year, .25 for leap year once ever 4 years). This results in a decimal representation of years. So 1 day short of 100 years would be something like 99.99726.

    Months is in particular are a problem as each month isnt the same number of days. Being exact means knowing which months are between 2 dates and accounting for the number of days in each of those months (including if Feb was leap or not). You could instead average # of days in a month in which case your answer for number of months isnt exact then.

    In any case if you could clarify the results you are looking for it would make it easier to give an exact answer. Hopefully the prior response solves the matter though
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  4. #4
    Forum Contributor
    Join Date
    06-16-2010
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    152

    Re: Odd Time result

    zerocool

    I didn't explain that too well!
    I was curious as to how many days he would be on his 100th birthday, then found the Microsoft article on date calcs and applied them, to find there were 100 extra days, which daddylonglegs has explained
    Nothing too serious, I just thought it would be fun to find out in days using an Excel formula.
    I have consistently found that it will be 35,625 days .

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

    Re: Odd Time result

    Quote Originally Posted by neil40 View Post
    I have consistently found that it will be 35,625 days .
    I assume that's a typo. In any 100 year period of time (at least since leap years obeyed the current rules) there will either be 36,525 days or 36524 depending on whether the last year of the century is a leap year or not, so for anybody alive today and reaching 100 years old that will be 36,525 because 2000 was a leap year, but 2100 isn't so, for example, between today and the same date in 100 years (16th January 2118) there are 36,524 days.

    Just a simple subtraction in Excel will give you that result:

    =DATE(2118,1,16)-DATE(2018,1,16)

  6. #6
    Forum Contributor
    Join Date
    06-16-2010
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    152

    Re: Odd Time result

    Yes it was a typo!!

    I meant to type 36,525

+ 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. Help with script that result in Run-time error
    By excelnabb in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-08-2018, 02:02 PM
  2. Replies: 4
    Last Post: 10-18-2016, 01:59 PM
  3. Elapsed time negative result
    By OllieKP87 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-02-2014, 02:30 PM
  4. [SOLVED] Two formula product different result 2% of time. WHy?
    By BRISBANEBOB in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-26-2013, 01:17 AM
  5. [SOLVED] Time intervals SUM unexpected result
    By NunoDinis in forum Excel General
    Replies: 11
    Last Post: 06-04-2012, 12:58 PM
  6. Specific number result if time value is more than...
    By Khaldon in forum Excel General
    Replies: 10
    Last Post: 05-18-2011, 05:26 AM
  7. add and subtract time and get result in time format
    By sanjay.ksg27 in forum Excel General
    Replies: 4
    Last Post: 12-31-2009, 07:21 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