+ Reply to Thread
Results 1 to 18 of 18

Need to calculate # of days per month between two dates even if end date is blank

  1. #1
    Registered User
    Join Date
    08-26-2015
    Location
    Pennsylvania
    MS-Off Ver
    2013
    Posts
    7

    Need to calculate # of days per month between two dates even if end date is blank

    I have to calculate the numbers of days per month a service has been used based on a start service dated and a discharge (end) date even if the service hasn't ended yet. I have a basic formula that break downs the number of days per each month between two dates, but when the end date is blank the formula just calculates as if end date were end of year. What i need is a way to have the formula calculate that if end date is blank it calculates number of days to current day.

    Here is the formula I am currently using: =MAX(0,MIN(EOMONTH(C$1,0),$B2)-MAX(C$1,$A2)+1)

    Here is a sample of my data set and the results from above formula:
    In Date End Date J F M A M J J A S O N D
    6/1/2015 8/30/2015 0 0 0 0 0 30 31 30 0 0 0 0
    6/2/2015 0 0 0 0 29 31 31 30 31 30 31 31
    6/2/2015 8/28/2015 0 0 0 0 0 29 31 28 0 0 0 0
    6/9/2015 0 0 0 0 22 31 31 30 31 30 31 31
    6/19/2015 0 0 0 0 12 31 31 30 31 30 31 31

    As you can see when no end date is available it calculates max # of days till end of year. I need it to calculate the blank days as if it were the current day. I've tried using ISBLANK but having trouble getting it to work. Please help. Thanks.

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Need to calculate # of days per month between two dates even if end date is blank

    =datedif(a2,if(isblank(b2),today(),b2),"d")
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    08-26-2015
    Location
    Pennsylvania
    MS-Off Ver
    2013
    Posts
    7

    Re: Need to calculate # of days per month between two dates even if end date is blank

    I'm sorry, I should have mentioned that I am not proficient at excel.

    How do I incorporate your formula into the one I have? I've tried to but get errors. I also tried to put yours in B cells but I get circular error messages.

    Thanks again.

  4. #4
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Need to calculate # of days per month between two dates even if end date is blank

    I was trying to point out that DATEDIF essentially does the same thing as your collection of cells.

    DATEDIF can be set to automatically count the number of days, months, or years between two dates.

    So DATEDIF(9/1/2015,9/10/2015,"d") = 9 days.

    If you know a start date and an end date, then you have the count of days without figuring out all the messy math of how many days are in each month.

    =datedif(a2,if(isblank(b2),today(),b2),"d")

    This formula is "the number of days from A2 to B2, and if B2 is blank, then from A2 to Current Day" as described in your original post.

  5. #5
    Registered User
    Join Date
    08-26-2015
    Location
    Pennsylvania
    MS-Off Ver
    2013
    Posts
    7

    Re: Need to calculate # of days per month between two dates even if end date is blank

    Ok. I understand. I just haven't explained my need well. I have a rather large set of data and I need to know the breakdown of days per month for the dates given. I need the break down by month so I can pool the usage data for a particular month and compare it to the number of available units for that month and get a percent use rate. Additionally, some of my dates run from 2014-2015 and I need the breakdown to keep last years days out of the monthly totals (thus the formula I was using). Another problem with my current formula, other that what I stated above, is that if I don't have an end date yet it calculates max days "used" for any remaining months in the year. I would like it to calculate to current date, even if blank so I can have most current data even for current month.

    Thanks for being patient and understanding. I appreciate your help.

  6. #6
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Need to calculate # of days per month between two dates even if end date is blank

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Give users here something to work with, instead of making us recreate all your work from scratch. Providing an example of work always attracts the most assistance.

  7. #7
    Registered User
    Join Date
    08-26-2015
    Location
    Pennsylvania
    MS-Off Ver
    2013
    Posts
    7

    Re: Need to calculate # of days per month between two dates even if end date is blank

    I hope this helps. In my attachment I have 2 sheets. Sheet1 is the exact data I am trying to use (no sensitive info). As you can see I have the start and end dates and the monthly break down as I'd like to see it. As you move down the column around row 49 you see that some entries do not have end dates. This is because they are still receiving our service. As you can see for these entries without a date the formula I am using appears to just calculate as if the service end date was at end of year and shows all remaining months as fully used up for that entry. What I would like is for the sheet to calculate these empty/still getting service as if today were the end date. Then I would like the sum of each month to transfer to Sheet2 to line 3 for their corresponding month.

    On Sheet2 I am trying to get a usage percentage for each month. So, row 3 will have actual units used for that month, and row 2 has available usage (we have 18 units X 31 days = 558 available). I would also like a formula for each month that would calculate the available usage (I.e #days in month X 18 = ???) it would be great if this calculated to the current date as well (like in the September cell, only 2 days this month so far times 18 = 36 available). This would give me a up to date percentage. **Note: I am aware we have more usage than availability at times. We are a drug and alcohol facility and my units are beds, we have extra beds for emergencies that we can not count as available, but we must count that the person was here. Therefor we may get usage rates higher that 100%.**

    Usage Rates.xlsx

    I hope this help. Thank you again.

  8. #8
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Need to calculate # of days per month between two dates even if end date is blank

    I see. Can you apply the same logic as my formula, with regard to the blank checking?

    =MAX(0,MIN(EOMONTH(C$1,0),IF($B2="",TODAY(),$B2))-MAX(C$1,$A2)+1)

  9. #9
    Registered User
    Join Date
    08-26-2015
    Location
    Pennsylvania
    MS-Off Ver
    2013
    Posts
    7

    Re: Need to calculate # of days per month between two dates even if end date is blank

    Yes!! That works. Thank you.

  10. #10
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Need to calculate # of days per month between two dates even if end date is blank

    And then for Sheet2:

    First, change B1:M1 to 1/1, 2/1, etc

    B2:
    =IF(MONTH(B1)<>MONTH(TODAY()),IF(DATE(YEAR(B1),MONTH(B1)+1,1)<TODAY(),DAY(DATE(YEAR(B1),MONTH(B1)+1,1)-1),0),DATEDIF(B1,TODAY(),"D"))*18

    C2:
    =SUM(Sheet1!C2:C78)

    D2:

    =IFERROR(B3/B2,"")

    and copy all three over

  11. #11
    Registered User
    Join Date
    08-26-2015
    Location
    Pennsylvania
    MS-Off Ver
    2013
    Posts
    7

    Re: Need to calculate # of days per month between two dates even if end date is blank

    These are great!!

    I only see one issue. With your B2 calculation it is only calculating for previous days of the month. For example the formula when applied to September gives a result of 18, but for our needs it should be 36 because today is the 2nd and this would most accurately reflect our usage for today as well. I'm not sure how to tweek the formula to reflect this.

  12. #12
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Need to calculate # of days per month between two dates even if end date is blank

    Just squeeze in a +1.

    =IF(MONTH(B1)<>MONTH(TODAY()),IF(DATE(YEAR(B1),MONTH(B1)+1,1)<TODAY(),DAY(DATE(YEAR(B1),MONTH(B1)+1,1)-1),0),(1+DATEDIF(B1,TODAY(),"D")))*18

  13. #13
    Registered User
    Join Date
    08-26-2015
    Location
    Pennsylvania
    MS-Off Ver
    2013
    Posts
    7

    Re: Need to calculate # of days per month between two dates even if end date is blank

    Perfect!! Your are the best!! Thank you so much.

    This can be marked as solved...

  14. #14
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Need to calculate # of days per month between two dates even if end date is blank

    Thanks for the feedback. Be sure to check out the User CP to see the message I sent you.


  15. #15
    Registered User
    Join Date
    02-07-2023
    Location
    United States
    MS-Off Ver
    0.8
    Posts
    18

    Re: Need to calculate # of days per month between two dates even if end date is blank

    Hello. Hi!

    The problem is simple, but the answer doesn't seem so...

    I'm trying to count the number of days per month per year between two dates.

    So for the following 2 dates:

    2013.12.15
    2014.02.18
    I would have something like:

    Year | Month | Days

    2013 12 16

    2014 01 31

    2014 02 18

    So, with 2 dates, i would get as many rows as months between then.

    I would like to achieve this using only a Select statement, but am completelu lost.

    Anyone one out there can crack this? 😀

  16. #16
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Need to calculate # of days per month between two dates even if end date is blank

    Quote Originally Posted by bojef View Post
    Hello. Hi!

    The problem is simple, but the answer doesn't seem so...

    I'm trying to count the number of days per month per year between two dates.

    So for the following 2 dates:

    2013.12.15
    2014.02.18
    I would have something like:

    Year | Month | Days

    2013 12 16

    2014 01 31

    2014 02 18

    So, with 2 dates, i would get as many rows as months between then.

    I would like to achieve this using only a Select statement, but am completelu lost.

    Anyone one out there can crack this? 😀
    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
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  17. #17
    Registered User
    Join Date
    02-07-2023
    Location
    United States
    MS-Off Ver
    0.8
    Posts
    18

    Re: Need to calculate # of days per month between two dates even if end date is blank

    thank you so much for your response. should i start the new thread with the same question

  18. #18
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Need to calculate # of days per month between two dates even if end date is blank

    Yes, that's the best way to post a question.

+ 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: 14
    Last Post: 04-06-2015, 09:19 PM
  2. 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
  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. Date Formula for days of the month, new dates starting on the 2nd of the month.
    By Kenn Jerger in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-04-2013, 01:31 AM
  6. [SOLVED] Formula needed to calculate working days in specified month between two dates
    By webfeet2 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-24-2013, 02:19 AM
  7. Calculate days in month after a given date
    By Grimace in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-20-2010, 12:41 AM

Tags for this Thread

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