+ Reply to Thread
Results 1 to 14 of 14

Count the number of months between 2 dates but only in a defined period

  1. #1
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    181

    Count the number of months between 2 dates but only in a defined period

    Hi there,

    I know I can use =DATEDIF(A1,B1,"m")+1 to calculate the months between 2 dates 01/05/2012 - 30/04/2013 =12.

    However, I wanted to try and count the number of months between 2 dates but only if they fall in the stated time period e.g:-

    01/01/2012 - 30/07/2014 but only the months between the time period from 01/05/2012 - 30/04/2013. So the answer in this case would be 12.

    01/07/2012 - 30/06/2014 between the time period from 01/05/2012 - 30/04/2013. So the answer is 10.

    I hope this makes sense and that someone can help me. It would be greatly appreciated.

    Thank you.

    Kind regards,

    Forrest

  2. #2
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Count the number of months between 2 dates but only in a defined period

    maybe something like this?

    =datedif(max(A1,date(2012,5,1)),min(B1,date(2013,4,30)),"m")+1

    re-post: sorry had the wrong number of parenthesis...

    instead of just A1, you can change it to max(A1,date(2012,5,1))
    same to B1, except it's min function...

    let me know if this is what you are looking for...
    Last edited by djapigo; 06-06-2013 at 02:23 PM.

  3. #3
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    181

    Re: Count the number of months between 2 dates but only in a defined period

    That's exactly what I wanted thank you so much!

    Regards,

    Forrest

  4. #4
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Count the number of months between 2 dates but only in a defined period

    Glad it worked... please go back to the original post and mark the thread SOLVED...

    Thanks for the rep, daddylonglegs...

  5. #5
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    181

    Re: Count the number of months between 2 dates but only in a defined period

    Sugar, just one other problem that I have realised. Between the below dates the formula calculates as i wanted it to but because of the way i described what i want i now release this won't quite work because the calculation for the below would add upto 13. I need it to add upto 12. I can see why but do not know how to resolve.
    01/01/2011 - 04/10/2011 =6
    05/10/2011 - 30/04/2012 =7

    I hope someone can help.

    Regards,

    Forrest

  6. #6
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Count the number of months between 2 dates but only in a defined period

    Try this...

    =DATEDIF(IF(B1<DATE(2013,4,30),A1,MAX(A1,DATE(2012,5,1))),MIN(B1,DATE(2013,4,30)),"m")+1

  7. #7
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    181

    Re: Count the number of months between 2 dates but only in a defined period

    it doesnt seem to work.

    first calculates to 10 and the second to 7. I tried to amend the calculation to :-

    =DATEDIF(IF(B1<DATE(2012,4,30),A1,MAX(A1,DATE(2011,5,1))),MIN(B1,DATE(2012,4,30)),"m")+1 but still couldnt get it to work.

  8. #8
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Count the number of months between 2 dates but only in a defined period

    I didn't know the years can change... ok, let me take a look again...

    What if the range is from 1/1/2011 - 4/10/2013? Should the two "fixed" dates be 1/5/2011 to 30/4/2012? or 2 years 1/5/2011 to 30/4/2013?
    Last edited by djapigo; 06-06-2013 at 05:10 PM.

  9. #9
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Count the number of months between 2 dates but only in a defined period

    Going back to the original formula... =DATEDIF(MAX(A1,DATE(2011,5,1)),MIN(B1,DATE(2012,4,30)),"m")+1

    If you want the "fixed dates" to depend on the year on the first date, then maybe we can try this formula...
    =DATEDIF(MAX(A1,DATE(YEAR(A1),5,1)),MIN(B1,DATE(YEAR(A1)+1,4,30)),"m")+1

    Let me know what you think...

  10. #10
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    181

    Re: Count the number of months between 2 dates but only in a defined period

    I am working it out in batches of financial years if that makes sense.

    So:

    FY12 = 01/05/2011 - 30/04/2012
    FY13 = 01/05/2012 - 30/04/2013
    FY14 = 01/05/2013 - 30/04/2014

    and then

    01/01/2011 04/10/2011
    05/10/2011 30/04/2012

    I am actually assessing for financial year FY12. But i would want the combination of the 2 differences to add up to 12 not 13. The first part you gave me worked great and i just needed to amend the years in the equation. I can see why it adds upto 13 because the end date of the first set of dates and the start dates of the second are in the same month but not sure if it is possible to stop this from happening. Thanks for all your help with this by the way. I thought it was a simplier question than what it has turned out to be.

  11. #11
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Count the number of months between 2 dates but only in a defined period

    Let's try this formula...
    =ROUND((MIN(B1,DATE(YEAR(A1)+1,4,30))-MAX(A1,DATE(YEAR(A1),5,1)))/30,0)

  12. #12
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    181

    Re: Count the number of months between 2 dates but only in a defined period

    Thank you so much I amended slightly to:-

    =ROUND((MIN(J176,DATE(2012,4,30))-MAX(I176,DATE(2011,5,1)))/30,0)

    and I will change for the batches. Once again thank you!

  13. #13
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Count the number of months between 2 dates but only in a defined period

    Very good... glad you're able to fix it to your liking...

    It's not a perfect formula by any means, but it should get you there for the majority of the time... it will all depend on your dates, especially if they start creeping near the middle of the months... I know because I work with dates all the time and still have not perfected how to calculate months between two dates...

    Let me know if you run into some problems...

  14. #14
    Registered User
    Join Date
    10-28-2014
    Location
    Silicon Valley, California
    MS-Off Ver
    XP
    Posts
    5

    Thumbs up Re: Count the number of months between 2 dates but only in a defined period

    =DATEDIF(MAX(D27,DATE(2015,1,1)),MIN(F27,DATE(2015,12,31)),"m")

    Thank you this helped me

+ 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