+ Reply to Thread
Results 1 to 11 of 11

Excel =Date and Leap Years

  1. #1
    Registered User
    Join Date
    10-13-2009
    Location
    PA
    MS-Off Ver
    Excel 2007
    Posts
    75

    Excel =Date and Leap Years

    Hello,

    I am looking to add years and months to a date to obtain some final date. Like an expiration date.

    However, I need it to factor in leap years which excel does not seem to do using the Date function unless I'm using it incorrectly.

    I've created a sample of what I'm looking for using the expiration date example. Excel simply seems to add year to year, month to month, without considering leap years in between.

    The format I am using is along the lines of:

    =DATE(YEAR(A1+B1),MONTH(A1+B2),DAY(A1)) where A1 is the starting date and B1 and B2 are years and months respectively.
    Attached Files Attached Files

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Excel =Date and Leap Years

    =date(year(a1) + b1, month(a1) + b2, day(a1))
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    10-13-2009
    Location
    PA
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Excel =Date and Leap Years

    Yes, that's what I am doing. It does not account for leap years doing it that way. All it does is numerically sum the years and months, checks to see if it's a real day (ex: Feb 30 bumped to March 2), and that's it. I need it to consider if the dates it's moving through are leap years and adjust the resulting date accordingly.
    Last edited by thesonofdarwin; 06-12-2010 at 11:45 PM.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Excel =Date and Leap Years

    It does not account for leap years doing it that way.
    For example, ...?

  5. #5
    Registered User
    Join Date
    10-13-2009
    Location
    PA
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Excel =Date and Leap Years

    For example it counts dates passing through year 2010 (365 days) the same as dates passing through 2012 (366 days).

    2 years on to 2011-01-25 should not be 2013-01-25 as there is an extra day in 2012. Excel doesn't seem to factor this in, however. This function makes it seem like 2011 and 2012 have the same number of days. It is summing the years without any consideration to years it advances through. The only consideration to leap years comes when the final date is generated and it checks to see if that day exists during that year. For example 2008-02-29 + 4 years = 2012-02-29 whereas 2009-02-29 + 3 years = 2011-03-01. That's as far as it takes leap years into consideration. I need it to add a day to the final date for every leap year that is added on to the initial date.
    Last edited by thesonofdarwin; 06-14-2010 at 12:09 AM.

  6. #6
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Excel =Date and Leap Years

    Perhaps you need to reconsider exactly where you're adding the time.

    The DATE function will behave as you suggest if you add the time to the day portion:

    Please Login or Register  to view this content.
    But you'll need to seriously consider the error you are incorporating, especially when you want to add a "standard" month of 30 days.

    Cheers,
    Last edited by ConneXionLost; 06-14-2010 at 02:01 AM.
    Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.

  7. #7
    Registered User
    Join Date
    10-13-2009
    Location
    PA
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Excel =Date and Leap Years

    Indeed. I have attempted to do that but it still would not correctly calculate because I'd manually have to enter +1 day for dates passing through a leap year. I've also tried using 365.242199 days in a year and 30.4368499 days in a month, but the result date ends up being more incorrect than not having tried to account for that extra day to begin with.

  8. #8
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Excel =Date and Leap Years

    Quote Originally Posted by thesonofdarwin View Post
    ... because I'd manually have to enter +1 day for dates passing through a leap year...
    Correct me if I'm wrong, but your initial description seemed to indicate that (adding a day) is precisely what you were trying to avoid. The point is, the DATE function IS allowing for leap years when you seem to be wanting it not to do so. Are you not expecting the function to add only 365 days (to reach an expiry) even when there is a leap year?

  9. #9
    Registered User
    Join Date
    10-13-2009
    Location
    PA
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Excel =Date and Leap Years

    No, I do not want it to only add 365 days (which is what DATE is doing). I want it to add however many days are in whichever years are being added on, accounting for leap years.

    If Excel's DATE did this, 2 years on to 2011-01-25 would be 2013-01-26, but Excel gives 2013-01-15 because it is not adding that extra day for leap years. But I need it to and I don't understand why it doesn't.

    For example: 2011-01-01
    2011 has 365 days, so one year on to that date is: 2012-01-01
    2012 has 366 days, so one additional year on to that date is: 2013-01-02
    Excel's DATE, however, yields 2013-01-01 which is not correct.

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

    Re: Excel =Date and Leap Years

    Hello thesonofdarwin, I think you are mistaken.

    When you add a year which is 366 days long you are already adding 366 days, if you add on another day you will be adding 367 days and effectively double-counting the leap day.

    Test that by putting 1-jan-2012 in A1 and 2-jan-2013 in B1 and in C1 use

    =B1-A1

    and format C1 as general

    result is 367, the number of days between those 2 dates
    Audere est facere

  11. #11
    Registered User
    Join Date
    08-20-2004
    Posts
    6

    Re: Excel =Date and Leap Years

    Actually, I am completely lost in this conversation.
    I agree that the confusion should be resolved before we try to help with any remaining issues. The major issue I could think of is what to do if the start day would be 29 February. However, with some IF function and using e.g. EOMONTH this could be overcome.

+ 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