+ Reply to Thread
Results 1 to 13 of 13

Calculate number of months in a specific year between two dates.

  1. #1
    Registered User
    Join Date
    05-19-2014
    Posts
    4

    Calculate number of months in a specific year between two dates.

    Hi

    Hoping you can help. I am trying to calculate the number of months in a specific year between two dates.

    For example.

    Start date 01/06/2012
    End Date 01/02/2013

    Number of months in 2012 = 6
    Number of months in 2013 = 2

    How can I write a formula to give me the answer of 6 & 2 from the start and finish dates?

    Appreciate any help as I have searched everywhere.
    Thanks

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Calculate number of months in a specific year between two dates.

    Hi,

    Why is the answer for 2012 exclusive of the start month, yet that for 2013 inclusive of the end month?

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Registered User
    Join Date
    05-19-2014
    Posts
    4

    Re: Calculate number of months in a specific year between two dates.

    A mistake in the example no reason. Thanks

  4. #4
    Valued Forum Contributor Saarang84's Avatar
    Join Date
    02-19-2009
    Location
    Chennai, India
    MS-Off Ver
    XL 2003 to 2010
    Posts
    812

    Re: Calculate number of months in a specific year between two dates.

    You can use the DATEDIF function to get the number of months between two dates.

    Assuming your Start date is in cell B1 and End Date is in cell B2, then you can get the total number of month passed between these 2 dates using,
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    However, do you want specifically to get the breakup of number of months passed across years? Can u be more specific with you exact need?
    If my assistance has helped, there is a reputation icon * on the left hand corner below the post - you can show your appreciation to the user who has helped in resolving your requirement.

    If your requirement has been solved please mark your thread as Solved.
    In the menu bar above the very first post, select Thread Tools, then select "Mark this thread as Solved".

    Kindly use [FORMULA] or [CODE] tags when posting your code.

    Regards,
    Sarang

  5. #5
    Registered User
    Join Date
    05-19-2014
    Posts
    4

    Re: Calculate number of months in a specific year between two dates.

    Hi

    Thanks for you response.

    To explain - a company wants to buy from me 10 boxes a month for a contract of the following duration;

    Start date 01/06/2012
    End Date 01/02/2013

    How many boxes will I sell in 2012
    How many boxes will I sell in 2013

    Hope this is clear

    Thanks

  6. #6
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Calculate number of months in a specific year between two dates.

    With your Start and End Dates in A1 and B1 respectively:

    =13-MONTH(A1)

    =MONTH(B1)

    Regards

  7. #7
    Registered User
    Join Date
    05-19-2014
    Posts
    4

    Re: Calculate number of months in a specific year between two dates.

    Thanks for your reply, how do I differentiate between the years. I.e. how many months fall into each year?

  8. #8
    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: Calculate number of months in a specific year between two dates.

    Or this

    =DATEDIF(A1,EDATE(A1,13-MONTH(A1)+DAY(A1))-1,"m")

    A
    B
    1
    6/1/2012
    7
    2
    2/1/2013
    11
    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

  9. #9
    Valued Forum Contributor Saarang84's Avatar
    Join Date
    02-19-2009
    Location
    Chennai, India
    MS-Off Ver
    XL 2003 to 2010
    Posts
    812

    Re: Calculate number of months in a specific year between two dates.

    Quote Originally Posted by XOR LX View Post
    With your Start and End Dates in A1 and B1 respectively:

    =13-MONTH(A1)

    =MONTH(B1)

    Regards

    Quote Originally Posted by AlKey View Post
    Or this
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    A
    B
    1
    6/1/2012
    7
    2
    2/1/2013
    11
    Hi,

    Note that, XOR LX's formula gives you count of boxes sold for each month, whereas Alkey's formula can be used only for the start date. For the end date, you need to use the below formula :
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    You need to prefix the DATEDIF formula with "13 - (minus)" for every completed year in the above formula.

    My formula,
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Gives you the total boxes sold between start and end dates.
    Last edited by Saarang84; 05-19-2014 at 10:28 AM.

  10. #10
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Calculate number of months in a specific year between two dates.

    Quote Originally Posted by Saarang84 View Post
    Note that, XOR LX's formula gives you count of boxes sold for each month
    Not sure what you mean - it gives a count of the number of months in each of the two years.

    Regards

  11. #11
    Valued Forum Contributor Saarang84's Avatar
    Join Date
    02-19-2009
    Location
    Chennai, India
    MS-Off Ver
    XL 2003 to 2010
    Posts
    812

    Re: Calculate number of months in a specific year between two dates.

    Quote Originally Posted by XOR LX View Post
    Not sure what you mean - it gives a count of the number of months in each of the two years.

    Regards
    Oops... My mistake. As per OP's requirement, the OP wants to calculate the number of boxes sold in those months.

    Then your formula should be changed as :
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    where x denotes the number of boxes sold each month. Then, as per the example given below, the formula would calculate
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    between Jun '12 till Dec '12 and
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    in Jan '13 and Feb '13.

    My formula also calculates the same and should be changed as
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    where x is 10. so, 90 boxes in both cases.
    Last edited by Saarang84; 05-19-2014 at 01:30 PM.

  12. #12
    Registered User
    Join Date
    09-09-2019
    Location
    London, England
    MS-Off Ver
    2017
    Posts
    2

    Re: Calculate number of months in a specific year between two dates.

    I have the same question as the above but the answers do not address it.
    In Col. A I have Contract ID, Col B a contract start date and in Col. C I have a contract end date.
    I want to out put the number of months that occur in the specific years 2017, 2018, 2019, 2020,2021 and 2022 in each contract.
    Example input (space delimited):

    ContractID StartDate EndDate
    AAA 01.04.2019 31.12.2033
    BBB 25.09.2020 10.05.2033
    CCC 06.06.2017 05.05.2020
    DDD 01.04.2019 07.04.2022

    Desired output (in Cols)(space delimited)
    Yr(2017) Yr(2018) Yr(2019) Yr(2020) Yr(2021) Yr(2022)
    0 0 8 12 12 12
    0 0 0 3 12 12
    6 12 12 5 0 0
    0 0 4 12 12 4

    Any suggestions?
    Last edited by horanio; 09-09-2019 at 11:49 AM.

  13. #13
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Calculate number of months in a specific year between two dates.

    Hello horanio. Welcome to the forum.

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Dave

+ 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: 8
    Last Post: 02-20-2014, 05:46 PM
  2. Replies: 2
    Last Post: 06-21-2012, 08:17 PM
  3. Replies: 4
    Last Post: 11-28-2011, 06:21 AM
  4. Replies: 3
    Last Post: 03-12-2009, 09:54 AM
  5. Replies: 5
    Last Post: 06-07-2008, 02:32 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