datedif...but month count

Pizzio

Active Member
Joined
Apr 28, 2005
Messages
268
I feel like I'm making this way more difficult than I need to.

01/18/22 - 02/18/22 - looking for a formula that will count the months to give the return of 2 for Jan/Feb
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
=DATEDIF(A1,A2,"m")+1
(based on your very small sample. if this isn't what you wanted, please post more examples)
 
Upvote 0
T202203a.xlsm
ABC
1
218-Jan-2218-Feb-222
315-Mar-225-May-223
4
2d
Cell Formulas
RangeFormula
C2:C3C2=MONTH(B2)-MONTH(A2)+1
 
Upvote 0
That won't work for Dec / Jan
You are correct...it didn't work in the calendar year transition. I used the datedif formula on 01/3022 - 02/20/22 and it still comes back as 1 month. This is with including the +1 in the calculation. Any thoughts?
 
Upvote 0
try
T202203a.xlsm
ABCD
1
218-Jan-2218-Feb-222
315-Mar-225-May-223
415-Dec-225-Jan-232
55-Mar-2131-May-213
630-Jan-2220-Feb-222
7
8
2d
Cell Formulas
RangeFormula
D2:D6D2=DATEDIF(EOMONTH(A2,-1)+1,EOMONTH(B2,0)+1,"m")
 
Upvote 0
You can also try =(YEAR(B2)-YEAR(A2))*12+MONTH(B2)-MONTH(A2)+1

T202203a.xlsm
ABCDE
1
218-Jan-2218-Feb-22222
315-Mar-225-May-22333
415-Dec-225-Jan-23222
55-Mar-2131-May-21333
630-Jan-2220-Feb-22222
7
2d
Cell Formulas
RangeFormula
C2:C6C2=DATEDIF(EOMONTH(A2,-1)+1,EOMONTH(B2,0)+1,"m")
D2:D6D2=DATEDIF(A2-DAY(A2)+1,EDATE(B2-DAY(B2)+1,1),"m")
E2:E6E2=(YEAR(B2)-YEAR(A2))*12+MONTH(B2)-MONTH(A2)+1
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,947
Members
449,095
Latest member
nmaske

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