Between 2 dates, Count number of times specific day of month occurs

XLBeginnr

New Member
Joined
Jan 12, 2020
Messages
3
Office Version
  1. 2013
Platform
  1. MacOS
Trying to work out how many specific dates occur between two dates, for example:

Start Date: 1/1/2020
End Date: 19/1/2021

Specific Date: 20th of month

Returns: 12

I've found this formula from the post below, but it only works for the same year and doesn't factor in differing years.

Code:
=1+MONTH(B2)-MONTH(B1)-(DAY(B2)<20)-(DAY(B1)>20)

 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Please try
=DATEDIF(EOMONTH(B1,0)+1,EOMONTH(B2,-1)+1,"m")+(DAY(B1)<21)+(DAY(B2)>19)
 
Upvote 0
Hi & welcome to MrExcel.
How about

Book1
ABC
101/01/202020
219/01/202112
List
Cell Formulas
RangeFormula
C2C2=1+DATEDIF(B1,B2,"m")-(DAY(B1)<C1)-(DAY(B2)>C1)
 
Upvote 0
@ Bo_Ry: your formula stumbles if the end date is 20-Jan-2020 -- it returns #NUM!.

@ Fluff: your formula stumbles if the end date is 20-Jan-2020 -- it returns 0; with the end date of 21-Jan-2020, it returns -1.

Here is my take on it:

=SUMPRODUCT(--(DAY(ROW(INDIRECT(B1&":"&B2)))=20))

Or a non-volatile version:

=SUMPRODUCT(--(DAY(ROW(INDEX(A:A,B1):INDEX(A:A,B2)))=20))
 
Upvote 0
@ Bo_Ry: your formula stumbles if the end date is 20-Jan-2020 -- it returns #NUM!.

@ Fluff: your formula stumbles if the end date is 20-Jan-2020 -- it returns 0; with the end date of 21-Jan-2020, it returns -1.

Here is my take on it:

=SUMPRODUCT(--(DAY(ROW(INDIRECT(B1&":"&B2)))=20))

Or a non-volatile version:

=SUMPRODUCT(--(DAY(ROW(INDEX(A:A,B1):INDEX(A:A,B2)))=20))
Yes! Thanks so much, the non-volitile one works great. Thanks so much!
 
Upvote 0
It looks fine here and it doesn't need slow array calculation.

Book1
BC
11/1/2019
2
31/1/2020
41/10/202012
51/19/202012
61/20/202013
71/21/202013
82/1/202013
92/10/202013
102/19/202013
112/20/202014
122/21/202014
133/1/202014
143/10/202014
153/19/202014
163/20/202015
173/21/202015
184/1/202015
194/10/202015
204/19/202015
214/20/202016
224/21/202016
Sheet2
Cell Formulas
RangeFormula
C4:C22C4=DATEDIF(EOMONTH($B$1,0)+1,EOMONTH(B4,-1)+1,"m")+(DAY($B$1)<21)+(DAY(B4)>19)
 
Upvote 0
I see, Problem when the start date and end date on the same month

Book1
BC
11/1/2020
2
31/1/20200
41/10/20200
51/19/20200
61/20/20201
71/21/20201
82/1/20201
92/10/20201
102/19/20201
112/20/20202
122/21/20202
133/1/20202
143/10/20202
153/19/20202
163/20/20203
173/21/20203
184/1/20203
194/10/20203
204/19/20203
214/20/20204
224/21/20204
Sheet2
Cell Formulas
RangeFormula
C3:C22C3=DATEDIF(EOMONTH($B$1,0)+1,EOMONTH(B3,0)+1,"m")+(DAY($B$1)<=20)-(DAY(B3)<20)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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