Calculate the number of 1st of the months

ClimbGuy

New Member
Joined
Jul 15, 2017
Messages
4
I have two dates and need to calculate the number of 1st of the months between them.

In order words if i have

January 31, 2017 to March 2, 2017 it should output 2
February 2, 2017 to February 28, 2017 should output 0
January 1, 2017 to February 1, 2017 should also output 1, (I know this could look like two, which is why I wanted to point it out)

Does anyone have any formula recommendations?

Thanks!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi,

Try this:


Book1
ABCDE
1January 31, 2017 to March 2, 2017 it should output 231-1-20172-3-20172
2February 2, 2017 to February 28, 2017 should output 02-2-201728-2-20170
3January 1, 2017 to February 1, 2017 should also output 1, (I know this could look like two, which is why I wanted to point it out)1-1-20171-2-20171
Sheet1
Cell Formulas
RangeFormula
E1=MONTH(IF(DAY(D1)>1,EOMONTH(D1,0),D1))-MONTH(IF(DAY(C1)>1,EOMONTH(C1,0),C1))
 
Upvote 0
Try this:

=SUMPRODUCT(--(DAY(ROW(INDEX(A:A,A1):INDEX(A:A,B1)))=1))-(DAY(A1)+DAY(B1)=2)
 
Upvote 0
@jorismoerings:

Just to mention: for your formula to work, both dates must be in the same year.
 
Upvote 0
@Tetra201:
Correct and aware. Not completely sure what OP means with
the number of 1st of the months between them
Cause given the statement your formula returns same result as mine while the OP quote could mean he wants the actual month number of the first month between.
Than both our formula's return an incorrect answer.
Let see what comes back.
 
Upvote 0
@jorismoerings:

My understanding of the "number of 1st of the months" between two dates is that, for example, Dec 25, 2016 to Jan 5, 2017 should return 1.
 
Upvote 0
@Tetra201:

I understand but change dates to Jan 31,2017 and Sep 2, 2017 and both formulas will return 8 while the the first month in between is February hence the number of the first month would be 2.
We're assuming our understanding is correct so that's why: let's wait and see.
 
Upvote 0
Hi Thank you for all the help!

To clarify I want to know the number of times there is a 1st of the month between two dates. There will be times when the dates span one more more calendar years.

Nov 31, 2016-Feb 1, 2017 should return 3

If the two dates are Jan 31, 2017 and Sept 2, 2017 the formula should return 8 since there are 8 1st of the months between those two dates (Feb 1, Mar 1, April 1, May 1, June 1, July 1, Aug 1, & Sept 1)
 
Upvote 0
That's exactly what my formula from Post #3 does. Have you tried it?

you are right only 30 days in November.

in terms of your formula =SUMPRODUCT(--(DAY(ROW(INDEX(A:A,A1):INDEX(A:A,B1)))=1))-(DAY(A1)+DAY(B1)=2)

I assume A1=date 1 and B1= date 2?
 
Upvote 0

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

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