+ Reply to Thread
Results 1 to 12 of 12

Number of Days in each month between two dates

  1. #1
    Registered User
    Join Date
    10-18-2012
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    56

    Number of Days in each month between two dates

    Hi,

    I am trying to write a formula that will show how many days for each month makes up a total date difference.

    For example, in cell A I have a start date, for example Jan 30 2015.

    In Cell B I have an End date, for example February 19.

    So in total, there are 20 days (End - Start).

    What I want to show is January made up 1 of those 20 days, and February made up 19 of those days, March made up 0 of those days, April make up 0 of those days, May made up 0 of those days, etc.

    The formula I used for M1 Value (it should technically be M2 (month 2 for February) is:
    =IF(DAY(E186)<=28,V186,DAY(E186))

    But I am wondering if this is the right "way" to go about this?
    Attached Images Attached Images
    Last edited by marshymell0; 06-12-2015 at 02:31 PM.

  2. #2
    Registered User
    Join Date
    08-17-2012
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: Number of Days in each month between two dates

    Use this formula to get the number of days in January
    Please Login or Register  to view this content.
    And use this formula to get the number of days in February
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-17-2012
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: Number of Days in each month between two dates

    Correction, it should be this for February
    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Number of Days in each month between two dates

    This works when D2 has the month name in it.

    I got the formula from here http://stackoverflow.com/questions/3...-certain-month
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Some people volunteer in soup kitchens or hospitals. I choose to make the world better by trying to help you with Excel. We're all learning.

    <---Click * Add Reputation for all helpful comments. It's like giving a smile.
    Forum Rules: How to mark your post [Solved] and have a happier, Excel enriched life.

  5. #5
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Number of Days in each month between two dates

    This will give you the number of days between dates and the days in each month between those dates.
    Attached Files Attached Files
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  6. #6
    Registered User
    Join Date
    10-18-2012
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: Number of Days in each month between two dates

    Hi,

    I noticed when using the formula,

    =IF(AND(EOMONTH(D$1,0)>=$B5,EOMONTH(D$1,-1)<=$B5),EOMONTH(D$1,0)-$B5,IF(AND(EOMONTH(D$1,0)>=$A5,EOMONTH(D$1,-1)<=$A5),$A5-EOMONTH(D$1,-1),IF(AND(EOMONTH(D$1,-1)>=$B5,EOMONTH(D$1,0)<=$A5),EOMONTH(D$1,0)-EOMONTH(D$1,-1),"")))

    on certain dates it is mis-counting. For example, when the start date is 3/31/2015 and end date is 4/5/2015, I am getting the correction number for March (0) bur for April it shows as 30. Another example is 4/5/2015 to 4/19/2015, it is showing as 25 days in April and not 14. Most of the other cells are correct when calculating.

    But when I use the other formula:
    =SUMPRODUCT((MONTH($B3+ROW($A$1:$A$10000)-1)=MONTH(1&E$1))*(($B3+ROW($A$1:$A$10000)-1)<=$A3))

    It works - interesting! I am going to see if I can see what the error is.
    Last edited by marshymell0; 06-13-2015 at 10:06 PM.

  7. #7
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Number of Days in each month between two dates

    There were at least 2 problems. One was an inconsistency in the date format and that wasn't being picked up. One date was MM/DD/YYYY and the other was DD/MM/YYYY. The other was a bad bit of logic.

    This version seems to calculate correctly. It calculates like a week. For example if today is Monday, a week from today is Monday i.e. +7 days. The start day isn't counted. This gives the same results when you subtract the Start Date from the End Date.

    Funny thing is, I couldn't get the SUMPRODUCT formula to calculate past April. It gave me all kinds of "funny" results...difference in date formats or something else, I haven't determined.
    Attached Files Attached Files
    Last edited by newdoverman; 06-14-2015 at 02:51 PM.

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Number of Days in each month between two dates

    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

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

    Re: Number of Days in each month between two dates

    If you use newdoverman's setup it would be sufficient to use this formula in D2 copied across and down

    =MAX(0,MIN($A2+1,EOMONTH(D$1,0)+1)-MAX($B2+1,D$1))

    If you want blanks instead of zeroes just custom format all cells as

    0;;

    See attached
    Attached Files Attached Files
    Audere est facere

  10. #10
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Number of Days in each month between two dates

    Nice one DDL

    If you don't want 0s and don't want Conditional Formatting, this longer version will eliminate the 0s

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

  11. #11
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Number of Days in each month between two dates

    Or, if using Excel 2007 or later...

    =IFERROR(1/(1/MAX(0,MIN($A2+1,EOMONTH(D$1,0)+1)-MAX($B2+1,D$1))),"")

  12. #12
    Banned User!
    Join Date
    10-29-2012
    Location
    Europe
    MS-Off Ver
    2013, 2016
    Posts
    318

    Re: Number of Days in each month between two dates

    or this in D2

    =MAX(0,MIN(EOMONTH(D1,0),$B2)-MAX(D1,$A2)+1)

    In A2 start date
    B2 End Date
    In D1, D2...D12 are date (01.01.2015, 01.02.2015....01.12.2015)
    Last edited by Indi_Ra; 06-15-2015 at 01:36 AM.

+ 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. How to calculate number of days between two dates by month
    By MHayward in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-06-2015, 12:26 PM
  2. [SOLVED] How to find number of days between two dates, by 6 month intervals
    By newyorktimes in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-25-2015, 08:36 PM
  3. [SOLVED] Calculate number of days in a month between two dates
    By schlomo87 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-04-2014, 12:32 AM
  4. Replies: 15
    Last Post: 06-03-2014, 02:08 PM
  5. [SOLVED] A formula to calc total number of days elapsed between two dates within any given month
    By paul.a.evans in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-03-2014, 01:29 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