+ Reply to Thread
Results 1 to 8 of 8

leap years and date calculation

  1. #1
    Registered User
    Join Date
    11-09-2017
    Location
    hamburg, germany
    MS-Off Ver
    2016
    Posts
    13

    leap years and date calculation

    Hi there,

    I have a problem to calculate the year in between dates. It is easy to get the days, but I need to devide an USD amount over the certain period and need to reflect how much money I need to pay per year. So the question is:

    How much money do I need to pay per year between 01/01/2010 and 31/12/2019 if the total amount during the period is USD 10,485,223.00?

    Initially I could just work with the general value of 365,25 days a year like this:

    A1: 01/01/2010
    A2: 31/12/2019
    A3: 10,485,223.00
    A4: =A2-A1 resulting in 3651 days
    A5: =(A2-A1)/365,25 resulting in 10,00 years
    A6: =A3/((A2-A1)/365,25) resulting in USD 1,048,953.08 per year.

    but this is not correct because its not 365,25 days during that period but the average year comes to 365,2 days (I manually did a average calculation with the relevant leap years 2012+2016)

    How can I consider the leap years in my calculation? i.e. the bolt value needs to be somehow a calculated average of the days per year during the A1&A2 period.

    Woudl apprecaite your help.

    Brgds
    Kai

  2. #2
    Valued Forum Contributor
    Join Date
    02-06-2013
    Location
    UK
    MS-Off Ver
    365
    Posts
    693

    Re: leap years and date calculation

    You can test for a leap year e.g. with =MONTH(DATE(G8,2,29))=2, if TRUE his is a leap year.
    G8 = year such as 2010.

    Regards

  3. #3
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,706

    Re: leap years and date calculation

    edit: disregard the below -- sorry, didn't think that through re: order of precedence for leap year !!

    if you needed to establish the decimal increment for your denominator (based on A1+A2) then perhaps:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    tbh, I am not sure how effective the denominator will be for partial year ranges, not tested...and there are no doubt more efficient methods.
    Last edited by XLent; 06-16-2020 at 08:56 AM.

  4. #4
    Registered User
    Join Date
    11-09-2017
    Location
    hamburg, germany
    MS-Off Ver
    2016
    Posts
    13

    Re: leap years and date calculation

    Holy formula.... My brain is too small to easily insert my data as I do not understand the formula. I tried to study but failed. Would it be possible to create an example and fill your formula on my above data given ?

    sorry and thank you in advanced.

    Brgds
    Kai

  5. #5
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,706

    Re: leap years and date calculation

    Sorry, updated below -- leveraging logic outlined by @RaulSerg

    So A1 is the start date, and A2 the end date -- you shouldn't need to modify anything else.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    the above basically creates 1 Feb 29 date per year in your range, and if XL sees that as a Feb date (month = 2) then you know it's a leap year, if XL says it's March 1st then you know it's not a leap year.

  6. #6
    Registered User
    Join Date
    11-09-2017
    Location
    hamburg, germany
    MS-Off Ver
    2016
    Posts
    13

    Re: leap years and date calculation

    Thank you very much. Yes, it looks like its working. still pretty difficult to understand how it works but yes, the result is good.

    But I made an easy example to my problem. So actually the Dates are in different cells.

    $B$6: 01.01.2020 (this data is fixed)

    $AA17: 31.12.2026 (this data is fixed by the row)

    So now I come across the error with the A:A in your formula. what is the solution?

    =365+SUMPRODUCT((MONTH(DATE(ROW(INDEX(A:A;YEAR(A1)+(TEXT(A1;"mmdd")>"0228")):INDEX(A:A;YEAR(A2)-(TEXT(A1;"mmdd")<="0228")));2;29))=2)+0)/DATEDIF(A1;A2+1;"y")

  7. #7
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,706

    Re: leap years and date calculation

    no, you don't need to worry about the A:A references, trust me that they can be left as-is, and will do their job, the only references you need to change are A1 + A2

    If B6 is always start then change all references to A1 to $B$6 and A2 to $AA17
    If the dates can alternate between which is start and which is end you would need to modify the DATEDIF to use MIN of dates for start, and MAX of dates for end.

    In XL Dates are just serial numbers, so the formula basically uses the ROW function to create an array of serial numbers where each serial number represents day 29 of month 2 for each year in the range.
    these serial numbers are then evaluated in context of being dates - i.e. which month do those serial numbers belong to -- if Month 2 then it's a leap year.

    people often use short (non-INDEX) syntax like below:

    =SUMPRODUCT(--(TEXT(ROW(INDIRECT($B$6&":"&$AA17));"mmdd")="0229"))

    this creates a serial number for every day in your range, and tests to see if it's Feb 29th.... but it uses iNDIRECT (so volatile), so I tend to avoid.

  8. #8
    Registered User
    Join Date
    11-09-2017
    Location
    hamburg, germany
    MS-Off Ver
    2016
    Posts
    13

    Re: leap years and date calculation

    Ahh, ok. This makes more sense. This helps me a lot. I will work with this formula now. Thank you very much. And have a great day! Awesome

+ 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] Age based on DOB; Accounts for leap years. Years old if >2, Months if <2 years old.
    By sharpmel in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 01-17-2013, 04:20 PM
  2. Dates and Leap Years
    By JEA in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-05-2011, 11:03 PM
  3. Date Differences and ignoring Leap Years
    By kieran54055 in forum Excel General
    Replies: 2
    Last Post: 09-20-2010, 11:51 AM
  4. Excel =Date and Leap Years
    By thesonofdarwin in forum Excel General
    Replies: 10
    Last Post: 06-15-2010, 03:31 AM
  5. Problem with displaying a date range for leap years
    By Parmo in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-02-2007, 06:27 PM
  6. How does Excel allow for leap years?
    By Neil in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-12-2006, 04:20 AM
  7. [SOLVED] Non Leap Years I want to show 28, leap years show 29 in an"IF"
    By bob@toyota-lift in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-20-2006, 04:30 PM
  8. [SOLVED] DATEDIF and leap years
    By Leyland in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 07-21-2005, 03:05 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