+ Reply to Thread
Results 1 to 10 of 10

Datedif

Hybrid View

  1. #1
    Registered User
    Join Date
    02-08-2012
    Location
    Western Mass
    MS-Off Ver
    Excel 2003
    Posts
    15

    Datedif

    My job requires a lot of calculation involving elapsed time in whole months. I use DATEDIF all the time to do this. I recently ran into one that doesn't make sense to me.

    Start Date: 01/01/1987
    End Date: 09/30/1987

    =DATEDIF(01/01/1987,09/30/1987,"M") returns a result of 8 months. I should be getting a result of 9 though, the completion of the month of September should grant a month. I tweaked the formula a bit to use a start date of 12/31/1986 but it still returned a result of 8 months. The only way I was able to get a result of 9 months was to use a start date of 12/30/1986 or an end date of 10/01/1987. I can't really do either of those things. Why isn't this working as expected.

    I didn't have any better luck trying to use YEARFRAC either. Does anyone have a better idea for elapse time functions?

    Thanks a bunch.

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Datedif

    You don't have to change the start or end dates 'On the sheet'.
    You can do it within the formula itself..

    Try
    =DATEDIF(A1,A2+1,"m")

  3. #3
    Registered User
    Join Date
    02-08-2012
    Location
    Western Mass
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Datedif

    Quote Originally Posted by Jonmo1 View Post
    You don't have to change the start or end dates 'On the sheet'.
    You can do it within the formula itself..

    Try
    =DATEDIF(A1,A2+1,"m")
    So from a conceptual perspective; if I want a DATEDIF function to consider the end date as a "completed" date I should add +1 to the end date so it actually ends it on the following day?

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Datedif

    If you want to use dates in the formula put them in quotes.
    Formula: copy to clipboard
    =DATEDIF("1/1/1987","9/30/1987","M")+1
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  5. #5
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Datedif

    Yeah, I think the logic of the function would be it counts how many months have 'Passed' between the 2 dates.
    If the End date is the last date of the month, then that month hasn't actually 'Passed' yet.

    I'm really just pulling that out of my keester, not sure if it's true or not.

  6. #6
    Registered User
    Join Date
    02-08-2012
    Location
    Western Mass
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Datedif

    I would have thought the same, and that's why I was so confused when =DATEDIF(12/31/1986,09/30/1987,"M") also returned 8 months.

  7. #7
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Datedif

    Actually this makes more sense...

    It takes the actual day number of the Start date (1)
    And count's how many day 1's occur between the 2 dates (not counting the start date)

    If the start date was say the 15th of a month, the count won't turn to 1 until the 15th of the next month.

    In the case where the start date is 29 30 or 31, and the next month doesn't have that many days, the count would incriment on the 1st of the following month.
    i.e. with 1/31/2016 as a start date, the count wouldn't be 1 until 3/1/2016
    Last edited by Jonmo1; 06-30-2016 at 12:00 PM.

  8. #8
    Registered User
    Join Date
    02-08-2012
    Location
    Western Mass
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Datedif

    That's pretty annoying, and it seems like it would create inaccurate results.

    I wonder if there's a more accurate way to calculate elapsed times. I need the end date to be included in the elapse time.

    For example, someone's first date of work is 01/01, and their last day is 09/30. They completed their shift on 09/30 and so they should get credit for have worked that day.
    Last edited by tedcahill2; 06-30-2016 at 12:07 PM.

  9. #9
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Datedif

    Well, what IS an accurate result ?

    Given that the number of days in a month is not consistent, it's really impossible to say with any precision how many months have passed between 2 dates.
    They did the best they could, and this is what they gave us.

    Perhaps an alternate method would be to use 30.4375 as a constant representing the number of days in a month
    =(365.25*4)/48

    Now do
    =(A2-A1+1)/30.4375

    That's going to give you a decimal number of the number of months, probably need to round it down
    =INT((A2-A1+1)/30.4375)

  10. #10
    Registered User
    Join Date
    02-08-2012
    Location
    Western Mass
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Datedif

    Thanks. I'll give it a shot.

+ 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. [SOLVED] DATEDIF - DATEDIF Calculation returning a negative for days or months
    By DaveBre in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-27-2015, 06:22 PM
  2. Datedif
    By lavoren in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 02-18-2015, 06:25 AM
  3. DATEDIF fx
    By aperfectalibi in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 02-17-2015, 08:59 AM
  4. how to use datedif
    By Enigma Trio in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-17-2014, 03:59 AM
  5. DateDif Average? Damn DateDif
    By UTCHELP in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 12-10-2012, 08:53 AM
  6. Excel 2007 : Datedif
    By mick2 in forum Excel General
    Replies: 3
    Last Post: 07-28-2010, 01:06 AM
  7. Excel 2007 : Datedif
    By mick2 in forum Excel General
    Replies: 2
    Last Post: 06-14-2010, 07:44 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