+ Reply to Thread
Results 1 to 10 of 10

Calculate number of months in year

  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 need to calculate the number of months a deal runs in 2012 dependant on the start and end date.
    I have attached a file with a basic view of this with COLUMN C showing the results I would like the formula to show. Column D has a formula which works for most but not all.
    As always many thanks for your help


    Regards
    Attached Files Attached Files
    Last edited by littlelax; 02-02-2012 at 08:55 AM.

  2. #2
    Registered User
    Join Date
    12-30-2011
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: Calculate number of months in year

    Hi there,

    You could try:

    =DATEDIF(A2,B2,"m")

    HTH,

    Fermented R

    Edit: Sorry just noticed you only need the months in 2012...will look into it!
    Last edited by Fermented Reptile; 02-02-2012 at 06:49 AM.

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Calculate number of months in year

    Try this with DATEDIF function...

    However, there is difference betwen your expected result and formula result:

    from 1.4. to 30.6. I think there should be 3 months (whole 4th, whole 5th and whole 6th month).
    Attached Files Attached Files

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

    Re: Calculate number of months in year

    Many thanks Zbor, This would give me the desired results bu when using in Excel 2007 I just get #VALUE. Is this a bug in 2007 and can it be fixed?

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Calculate number of months in year

    I'm using 2007 and it works.. Maybe you need to change date formats in formula...

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

    Re: Calculate number of months in year

    I have tried changing the formats but still no joy. I have re-attached in case you are able to see the error. Thankyou for your help
    Attached Files Attached Files

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Calculate number of months in year

    I changed the format of the date text strings:

    =DATEDIF(MAX(MIN(A2:B2),"1/1/2012"),MIN(MAX(A2:B2),"31/12/2012"),"m")+1

    Format result as general.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


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

    Re: Calculate number of months in year

    Many thanks that works great.

  9. #9
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Calculate number of months in year

    Quote Originally Posted by zbor View Post
    from 1.4. to 30.6. I think there should be 3 months (whole 4th, whole 5th and whole 6th month).
    In fact DATEDIF counts entire months between the 1st of the month and the 1st of the next month
    So 1.4 till 30.6 is only 2 months for this fucntion

  10. #10
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Calculate number of months in year

    Yes, you are right..
    But in example I've put +1 to match most of other cases and my point was that in this cases result should be 3 (and not 2).

    Or, by same logic, in those could be 2 but in other one less.

+ 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