Excel 2007 Calc Nbr of Mths between dates

KrazyKasper

Board Regular
Joined
Aug 28, 2008
Messages
87
I need to calculate the number of months between two dates, but if the earlier date is not the first of the month then use the first of the next month as the earlier date.

I tried modifying the formula:
=(YEAR(LDate)-YEAR(EDate))*12+MONTH(LDate)-MONTH(EDate)

but have not had any success.

Using the following dates as an example:
EDate 11/4/06
LDate 5/31/11
The result should be: 54

Using the following dates:
EDate 11/1/06
LDate 5/31/11
The result should be: 55

Any help is appreciated.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
There probably is a easier way, built in function or something, but this worked for me.

Code:
=(YEAR(Ldate)-IF(AND(MONTH(Edate)=12,DAY(Edate)<>1),YEAR(Edate)+1,YEAR(Edate))-1)*12+(13-IF(DAY(Edate)=1,MONTH(Edate),MONTH(EDATE(Edate,1))))+MONTH(Ldate)

Note that the capitalized EDATE is not your early date, it is a built in function do not change that. This formula follows the logic of if it is not the first of the month go to next month for Edate but not Ldate.
 
Upvote 0
Substituting the cell numbers (e.g., A1 and A2) in place of LDate and EDate gives me -1 when formatted as "General" and ##### when formatted as a date (short or long).

Am I missing something?
 
Upvote 0
To obtain the results in your examples, add the portion in red to your original equation.

Code:
=(YEAR(LDATE)-YEAR(EDATE))*12+MONTH(LDATE)-MONTH(EDATE)[COLOR=red]+IF(DAY(EDATE)=1,1,0)[/COLOR]
 
Upvote 0
You could also get the same results using DATEDIF function like this

=DATEDIF(Edate-DAY(Edate-1),Ldate,"m")
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

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