+ Reply to Thread
Results 1 to 11 of 11

Count Last Days of Months Between Two Dates

  1. #1
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Count Last Days of Months Between Two Dates

    I need to calculate the number of last days of months between two dates. So, for example,

    8 Dec 13 to 11 May 14, the answer should be 5 as there have been 5 month ends between these two dates.

    Can anyone help, please?

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

    Re: Count Last Days of Months Between Two Dates

    Perhapes this:

    =TEXT(B1-A1-(DAY(B1)>=DAY(A1)),"m")

  3. #3
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Count Last Days of Months Between Two Dates

    Quote Originally Posted by zbor View Post
    Perhapes this:

    =TEXT(B1-A1-(DAY(B1)>=DAY(A1)),"m")
    I tried this and it almost works. Each time I test it with different dates it is one month out. The result to the example in the OP shows 6 when it should be 5 so it is one month over. But when I use other dates that contain the last day of a month, e.g. 31 Dec 13 to 30 April the result is one month under.

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

    Re: Count Last Days of Months Between Two Dates

    How about this:

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

  5. #5
    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: Count Last Days of Months Between Two Dates

    You can also use this

    =DATEDIF(A2,B2,"m")

    A
    B
    C
    2
    12/8/2013
    5/11/2014
    5
    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

  6. #6
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Count Last Days of Months Between Two Dates

    Quote Originally Posted by zbor View Post
    How about this:

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

    =DATEDIF(A2,B2,"m")

    A
    B
    C
    2
    12/8/2013
    5/11/2014
    5
    Both of these work (ish). I've tested a number of different dates and when both start and end dates fall on the end of a month they don't count correctly.

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

    Re: Count Last Days of Months Between Two Dates

    Can you elaborate this?

    because I get with both approach:

    Please Login or Register  to view this content.

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Count Last Days of Months Between Two Dates

    Try

    =DATEDIF(A1,B1,"m")+(DAY(A1)>DAY(B1))+(MONTH(B1)<>MONTH(B1+1))

    A1=start date
    B1=end date

  9. #9
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Count Last Days of Months Between Two Dates

    Quote Originally Posted by Jonmo1 View Post
    Try

    =DATEDIF(A1,B1,"m")+(DAY(A1)>DAY(B1))+(MONTH(B1)<>MONTH(B1+1))

    A1=start date
    B1=end date
    This one works. Thanks for that (thanks given).

  10. #10
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Count Last Days of Months Between Two Dates

    Quote Originally Posted by zbor View Post
    Can you elaborate this?

    because I get with both approach:

    Please Login or Register  to view this content.
    3 is incorrect because there are 4 end of month days in your example. 31 Dec, 31 Jan, 28 Feb and 31 Mar.

    Thanks for your help though (thanks given).

  11. #11
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Count Last Days of Months Between Two Dates

    You're welcome.

+ 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. Difference between two dates in months and days
    By pleiadeez7 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-24-2013, 01:54 PM
  2. [SOLVED] Count days and months between two dates
    By nurer in forum Excel General
    Replies: 5
    Last Post: 05-23-2012, 10:53 AM
  3. Count days depending on months
    By asifakhtar in forum Excel General
    Replies: 1
    Last Post: 10-13-2009, 02:25 PM
  4. [SOLVED] Number of years/months/days between 2 dates
    By Deborah in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-07-2006, 06:30 AM
  5. [SOLVED] how many months and days between two dates?
    By shopgirl in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 02-12-2006, 04:10 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