+ Reply to Thread
Results 1 to 13 of 13

Determine # of days between two dates for each calendar year

  1. #1
    Registered User
    Join Date
    07-30-2013
    Location
    New Jersey, US
    MS-Off Ver
    Excel 2010
    Posts
    33

    Determine # of days between two dates for each calendar year

    Thank you for taking the time to read through this.

    I am trying to develop a formula or way of taking the number of days between two dates and allocating them by calendar year.

    For example:

    Date 1: 3/4/2014
    Date 2: 5/1/2015

    I would want to have a formula in 2 different columns.

    Column 1: Tells me how many days between Date 1 and Date 2 fall in the 2014 Calendar Year (I believe this should be 303 days [12/31/2014 minus 3/4/2014])
    Column 2: Tells me how many days between Date 1 and Date 2 fall in the 2015 Calendar Year (I believe this should be 121 days [5/1/2015 minus 1/1/2015])

    Any suggestions?
    Last edited by gmazz; 03-12-2015 at 04:04 PM.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,632

    Re: Determine # of days between two dates for each calendar year

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Best Regards,

    Kaper

  3. #3
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Determine # of days between two dates for each calendar year

    Assuming your dates are in A1 and A2:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Spread the love, add to the Rep

    "None of us are as smart as all of us."

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,632

    Re: Determine # of days between two dates for each calendar year

    PS. this of course raises "old question" - if it is new years eve, do we have 1 day of old year left or 0? And same on New Year - already first day of year or still less than 1 (0) passed.
    Anyway adapt the above to your taste and it shall work nicely. As for the more general form, I'd opt for:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    etc.

  5. #5
    Registered User
    Join Date
    07-30-2013
    Location
    New Jersey, US
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Determine # of days between two dates for each calendar year

    Thanks for your replies Kaper and mcmahobt. I am not too worried about missing a day. I just want the allocation to be correct. I have attached a sample of how the layout needs to look. I have a data set that I continually add to each month so I need to have the rows for all the new data I receive. So the columns needs to be for the days in each calendar year.

    Column C needs to take the number of days between the data entered in each row in column A and B. But Column C should only show the days that fall into the 2014 Calendar Year. So for example row 3 reads:

    A3: 8/4/2014
    B3: 6/3/2015
    C3: needs to show the # of days that fall into the 2014 calendar year. Meaning the difference between 12/31/2014 and 8/4/2014.
    D3: needs to show the # of days that fall into the 2015 calendar year. Meaning the difference between 6/3/2015 and 1/1/2015.
    E3: needs to show the # of days that fall into the 2016 calendar year. In this case, the formula should read that none of the dates in A3 or B3 fall in the 2016 calendar year, and therefore it should read 0

    The other part that makes this a bit complicated, is that if you notice on row 7, both dates in column A and B fall in 2014. Therefore C3 would just be the number of days between B7 and A7. Not the number of days from 12/31/2014 to A7. The formula would need to account for this so that when I drag it down it will work for all types of scenarios with the dates. Any thoughts???
    Attached Files Attached Files
    Last edited by gmazz; 03-11-2015 at 04:15 PM.

  6. #6
    Forum Expert
    Join Date
    12-09-2014
    Location
    Trakai, Lithuania
    MS-Off Ver
    2016
    Posts
    1,296

    Re: Determine # of days between two dates for each calendar year

    If properly understood.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    07-30-2013
    Location
    New Jersey, US
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Determine # of days between two dates for each calendar year

    Czeslaw,

    The formula technically works except it does not account for all contingencies. If you notice, on row 7, both the dates in A7 and B7 fall in the 2014 calendar year. When this is the case, the formula needs to take the # of days between A7 and B7. In your formula, it is just taking the # of days between 12/31/2014 and A7.

    Also, just hypothetically speaking, lets say we added a new row of dates on line 18. A18 reads 3/8/2015 and B18 reads 2/16/2016. If this were the case, your formulas would read C18 as 0, D18 as 412, and E18 as 47. D18 would be incorrect as you can't have more than 365.

    This is why I have been struggling because I believe this formula will be require a few nested If statements or something. It isn't as easy as it appears.
    Last edited by gmazz; 03-11-2015 at 05:06 PM.

  8. #8
    Forum Expert
    Join Date
    12-09-2014
    Location
    Trakai, Lithuania
    MS-Off Ver
    2016
    Posts
    1,296

    Re: Determine # of days between two dates for each calendar year

    Please look at this option.
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    12-09-2014
    Location
    Trakai, Lithuania
    MS-Off Ver
    2016
    Posts
    1,296

    Re: Determine # of days between two dates for each calendar year

    Now it is really accurate.
    Attached Files Attached Files

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

    Re: Determine # of days between two dates for each calendar year

    If you show just the year in the header row, e,g, in C2 you have 2014, in D2 you have 2015 etc. then you can use this formula in C3 copied across and down

    =MAX(0,MIN(DATE(C$2+1,1,0),$B3)-MAX(DATE(C$2,1,1),$A3)+1)

    That will count start and end date, e.g. Start date today, end date tomorrow counts 2 - that can be adjusted if you want but if today until tomorrow counts 1 which day are you excluding?

    Note: this works for any date ranges, even if you start in 2013 or end in 2017, with a single consistent formula that doesn't need to be changed
    Last edited by daddylonglegs; 03-12-2015 at 04:48 AM.
    Audere est facere

  11. #11
    Registered User
    Join Date
    07-30-2013
    Location
    New Jersey, US
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Determine # of days between two dates for each calendar year

    Thank you all for helping me solve this. Daddylonglegs, your method seems to work for all the contingencies I have. There is however, another caveat I need to include.

    I have attached a sample with the extra contingencies I need to incorporate. I was thinking of doing this formula in new columns (H, I, and J). I have manually entered the values in columns H, I, and J. This should help you as a guide when you are developing formulas.

    1. The formula in columns C, D, E, H, I, and J needs to show the # of days as negative if the value in the F column is negative. It also needs to show the # of days as 0 if the value in column F is 0. I have added this to the formula in columns C, D, and E but if you know a better way to do this than feel free to revise the formula.

    2. Columns H, I, and J are called "Earned Days". I need this columns to accomplish something a bit different than columns C, D, and E. You will see a date highlighted in yellow in cell G1. I need columns H, I, and J to tell me the # of days in each calendar year that do not exceed the date in G1.

    For Example:

    Row 3 shows A3 as 8/4/2014 and B3 as 6/3/2016. G1 shows as 2/28/2015. Therefore the formulas in column H, I, and J should return the following figures:

    H3: Needs to show the total # of calendar days in 2014 that do not exceed the value in G1. Because G1 has a date that is greater than any date in 2014, the value in H3 would be the same as in C3. (150)
    I3: Needs to show the total # of calendar days in 2015 that do not exceed the value in G1. Because G1 has a date that IS in 2015, we need to take the # of days from A3 to G1 (but only the days that fall into the 2015 Calendar Year). In this case, the formula should take the # of days from 1/1/2015 to 2/28/2015. But the formula needs to work where if for example, A3 read 1/4/2015, than it would take the # of days from 1/4/2015 to 2/28/2015.
    J3: Needs to show the total # of calendar days in 2016 that do not exceed the value in G1. Because G1 has a date that is less than any date in 2016, the value in J3 would be 0.

    ***Also, the formula needs to follow the same idea of columns C, D, and E, where if the value in column F is negative, than the values in H, I, and J will be negative. If the value in F equals 0, than the values in H, I, and J will equal 0.***

    I am really hoping to have a consistent formula that I can drag down as I get new data, and I can add new columns for future years where the formula does not need to be changed, and all I need to do is copy it from the adjacent column.

    I apologize if this is a bit confusing. I appreciate all your help and if you need me to explain anything again I am more than willing to.
    Attached Files Attached Files

  12. #12
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,632

    Re: Determine # of days between two dates for each calendar year

    I think following meets your request pretty well:
    C3 and copy right/down as needed:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    and H3 and copy right/down as needed:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    07-30-2013
    Location
    New Jersey, US
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Determine # of days between two dates for each calendar year

    Kaper that seems to work! Thank you all so much for all the help you have provided. I have been developing much longer formulas that still never did what I needed them to do. You have saved me so much time and frustration. Can't thank you enough!

+ 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. Replies: 7
    Last Post: 12-24-2014, 05:03 PM
  2. Replies: 1
    Last Post: 12-24-2014, 03:52 PM
  3. Replies: 2
    Last Post: 07-31-2013, 02:00 PM
  4. Input a year to determine the start date for 4-4-5 Calendar Year.
    By mak1176 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-25-2013, 10:34 AM

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