How many months within 2 date ranges were in specific years/months?

slam

Well-known Member
Joined
Sep 16, 2002
Messages
919
Office Version
  1. 365
  2. 2019
Hi everyone!

Quite a spreadsheet project I'm working on today, but I'm just a bit stumped on one little thing.

I'll explain a simple version of it that will probably be enough to get me going.

I have a date range in columns E & F, then in column G I've calculated the number of months within this date range with a DATEDIF. Now the part I'm stuck on is in column H, I need to calculate the number of 2020 Jan through Oct months that occur within this date range, and the same thing in column I for 2021, so the highest value possible for H or I is 10 for the 10 Jan through Oct months.

Here you can see a mockup where I've manually populated the highlighted H and I values to show the results I need to automate.

2021-10-26 Investment Comparison.xlsx
EFGHI
1Start DateEnd DateTotal Project Months2020 Jan through Oct Months2021 Jan through Oct Months
201/01/202111/30/2021101010
304/07/201703/31/20203530
412/01/201701/29/202137101
505/01/201706/30/20203760
602/01/201802/28/20202402
704/01/201801/31/20202110
809/27/202009/30/20211299
Project
Cell Formulas
RangeFormula
G2:G8G2=DATEDIF(E2,F2,"m")


Any suggestions? Thanks!

EDIT: Row 8 of my example should be 2 & 9, not 9 & 9. Sorry.
 
Last edited by a moderator:
If I2 should be 10 then surely G2 should be 11 :unsure:

Hmm, that's a good point. DATEDIF is rounding down by default? Or not counting a month unless its a full month? Can I make it round up somehow?
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
It depends at what point it should round up. I haven't checked it in detail but from past observations, I think that the day in the end month has to be equal to or greater than the day in the start month in order for that month to be counted.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top