I have a worksheet that has a start date and an end date. I need to get the number of months between these dates. I used the formula =MONTH(B1)-MONTH(A1) to get this #. However, this formula fails when my dates span several years — if the start date is 1/1/2014 and the end date is 1/1/2015, then it returns “1” when I want to get “12”.
Then I tried DATEDIF(A1,B1,"m") to get the number of months between dates, and that worked. However, my problem can be reduced to the following example:
Situation 1:
Start date: 1/5/2014
End date: 3/1/2014
"MonthDif": 2
DateDif: 1
Situation 2:
Start date: 1/5/2014
End date: 3/10/2014
"MonthDif": 2
DateDif: 2
As you can see, the DATEDIF function returns # full months, while my month - month function returns the number of months "occupied" by the difference between the start and end dates, regardless of whether they are full months.
I need the number of months, regardless of whether the months are full, for any period of time! Basically, I need what MONTH(B1)-MONTH(A1) returns, except that it will work for several years.
In addition, I was considering creating a custom VBA function to achieve the above. If anyone has any suggestions,
source share