+ Reply to Thread
Results 1 to 8 of 8

Calculate number of months in year

Hybrid View

  1. #1
    Registered User
    Join Date
    12-30-2011
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    13

    Calculate number of months in year

    Hi,

    I would like to calculate the number of months in a period such as 2012 dependant on a start and end date. The attached spreadsheet has an example of this but basically i need:

    Start Date = 01/08/2011
    End Date = 31/05/2012
    Calc should be = No. of months in 2012 = 5

    I need this to work for any start and end date criteria.

    As always many thanks for your help
    Attached Files Attached Files

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Calculate number of months in year

    Hi

    Pls can you explain me, why 01/01/12---31/12/12=12

    and 01/05/12---31/08/12= 3 ??

    I think that or first result must be 11, or second result, must be 4!!

    Is it corect??
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

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

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  3. #3
    Registered User
    Join Date
    12-30-2011
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Calculate number of months in year

    Hi Fotis1991,

    Apologies, you are correct the 01/01/2012-31/12/2012 should show 11

  4. #4
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Calculate number of months in year

    hi please check attachment
    Attached Files Attached Files
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  5. #5
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Calculate number of months in year

    ..So in D5

    =MONTH(B5)-MONTH(A5)

    Hope to helps you

  6. #6
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,414

    Re: Calculate number of months in year

    This seems to do what you want:

    =IF(B5>DATE(2012,12,31),12,IF(B5<DATE(2012,1,1),0,MONTH(B5)))-IF(A5>DATE(2012,12,31),0,IF(A5<DATE(2012,1,1),0,MONTH(A5)-1))

    although it returns 4 for your third example (1/05/2012 to 31/08/2012) instead of 3. However, if you count the months in that range you will find that there are 4. The formula will count part months as whole months, so 31/01/2012 to 1/03/2012 will return 3.

    Hope this helps.

    Pete

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,699

    Re: Calculate number of months in year

    Try this formula

    =IFERROR(DATEDIF(MAX(DATE(2012,1,0),A5),MIN(DATE(2013,1,0),B5),"m"),0)
    Audere est facere

  8. #8
    Registered User
    Join Date
    01-25-2012
    Location
    UAE
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Calculate number of months in year

    use this sample function

    =DATEDIF(A5,B5,"m")

+ 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