Conernesto

asked on

# Excel formula that tells you the number of months

Hi,

I have an Excel spreadshet that list in a column the acquisition dates. I need to know the number of months from the acquisition date to June 2012 for each acquisition date. Below is a sample of the column with the acquisition dates. I added the months for the first acquisition date and I came up with 44 months. How do I do this with a formula?

Acquisition Date How many Months to June 2012?

(YYYY-MM-DD

2008-11-14 Should be 44 months

2009-07-15

2010-01-01

I have an Excel spreadshet that list in a column the acquisition dates. I need to know the number of months from the acquisition date to June 2012 for each acquisition date. Below is a sample of the column with the acquisition dates. I added the months for the first acquisition date and I came up with 44 months. How do I do this with a formula?

Acquisition Date How many Months to June 2012?

(YYYY-MM-DD

2008-11-14 Should be 44 months

2009-07-15

2010-01-01

http://support.microsoft.com/kb/214134

ASKER CERTIFIED SOLUTION

membership

This solution is only available to members.

To access this solution, you must be a member of Experts Exchange.

ASKER

How do I enter the B1 date?

My acquistion date is on celll A1 and it's equal to "2008-11-14"

My acquistion date is on celll A1 and it's equal to "2008-11-14"

=DATE(2012,6,1)

Kevin

Kevin

Hi,

I see 43 months using this in-cell formula:

=DATEDIF(A3,DATE(2012,6,DAY(A3)),"m")

Where [A3] is the cell that contains 2008-11-14.

(See attached)

BFN,

fp.

Q-28133886.xls

I see 43 months using this in-cell formula:

=DATEDIF(A3,DATE(2012,6,DA

Where [A3] is the cell that contains 2008-11-14.

(See attached)

BFN,

fp.

Q-28133886.xls

ASKER

Is there a way to increase this by one so we get 44 months?

=DATEDIF(A3,DATE(2012,6,DAY(A3)),"m")+1

:)

:)

Use this date in B1:

=DATE(2012,6,30)

Kevin

=DATE(2012,6,30)

Kevin

A note about my solution. I prefer not to use DATEDIF because it's support by Microsoft has been spotty and it has bugs. The DATEDIF function was introduced in Excel version 5.0 as a 1-2-3 compatibility feature. It was not documented until Excel 2000 and was subsequently dropped from the help in Excel 2002. It is a built-in function that operates just as any other built-in function operates. It does not produce correct results if the start date is the 29th or later and the end date is in the month following a month with fewer days than in the day of month in the start date. For example, if the start date is January 31, 2006 and the end date if March 1, 2006, the MD value is -2.

Kevin

Kevin

ASKER

Kevin,

I will use your first answer I replaced the date for B1 with = Date(2012,7,30) instead of =Date(2012,6,30) and I go the first answer that I was looking for "44".

Thank you.

Conernesto

I will use your first answer I replaced the date for B1 with = Date(2012,7,30) instead of =Date(2012,6,30) and I go the first answer that I was looking for "44".

Thank you.

Conernesto

You're welcome.

PS. I have never had any trouble using the DATEDIF() in-cell function, nor the Visual Basic for Applications equivalent, DATEDIFF(), that

PS. I have never had any trouble using the DATEDIF() in-cell function, nor the Visual Basic for Applications equivalent, DATEDIFF(), that

*is*documented within the help file for Microsoft Excel 2003 (my version of Excel of choice).
For an illustration for why, like Kevin, I almost never use DATEDIF, enter these in an Excel worksheet:

A1: 1/31/2006

B1: 3/1/2006

C1: =DATEDIF(A1,B1,"y") & " years, " & DATEDIF(A1,B1,"ym") & " months, " & DATEDIF(A1,B1,"md") & " days"

You get the following non-sensical result:

0 years, 1 months, -2 days

Or this example, with a result that is less nonsensical, albeit still (IMHO) wrong:

A1: 1/29/2006

B1: 2/28/2006

C1: =DATEDIF(A1,B1,"y") & " years, " & DATEDIF(A1,B1,"ym") & " months, " & DATEDIF(A1,B1,"md") & " days"

Returns: 0 years, 0 months, 30 days

Also, please note that despite the similarity in names, DATEDIF and DateDiff use a completely different method to do calculations. Consider:

A1: 12/31/2012

B1: 1/1/2013

C1: =DATEDIF(A4,B4,"y")

That will return zero. However, DateDiff using the same parameters will return 1, because while DATEDIF is attempting to measure the number of "full" intervals between two dates, DateDiff counts only the time interval boundaries between two dates.

A1: 1/31/2006

B1: 3/1/2006

C1: =DATEDIF(A1,B1,"y") & " years, " & DATEDIF(A1,B1,"ym") & " months, " & DATEDIF(A1,B1,"md") & " days"

You get the following non-sensical result:

0 years, 1 months, -2 days

Or this example, with a result that is less nonsensical, albeit still (IMHO) wrong:

A1: 1/29/2006

B1: 2/28/2006

C1: =DATEDIF(A1,B1,"y") & " years, " & DATEDIF(A1,B1,"ym") & " months, " & DATEDIF(A1,B1,"md") & " days"

Returns: 0 years, 0 months, 30 days

Also, please note that despite the similarity in names, DATEDIF and DateDiff use a completely different method to do calculations. Consider:

A1: 12/31/2012

B1: 1/1/2013

C1: =DATEDIF(A4,B4,"y")

That will return zero. However, DateDiff using the same parameters will return 1, because while DATEDIF is attempting to measure the number of "full" intervals between two dates, DateDiff counts only the time interval boundaries between two dates.

Conernesto,

It would help if you provided an explicit definition for how you want to count the months.

Patrick

It would help if you provided an explicit definition for how you want to count the months.

Patrick

...while DATEDIF is attempting to measure the number of "full" intervals between two dates, DateDiff counts only the time interval boundaries between two dates.

As long as you are aware of the difference, & make an allowance for this (like simply adding one to the total, as above, or subtracting one from the total, if required), usage is possible.

PS. In your examples, Patrick, I would simply use C1=B1-A1 to provide the number of days between the two dates.

PPS. For completeness, Chip Pearson has a "gotcha" note on the use of =DateDif(...) when using dates spanning leap years:

[ http://www.cpearson.com/excel/datedif.aspx ]

---

DATEDIF And Leap Years

When calculating date intervals, DATEDIF uses the year of Date1, not Date2 when calculating the yd, ym and md intervals. For example,

=DATEDIF(Date1,Date2,"md")

returns 28 for Date1 = 1-Feb-2007 and Date2 = 1-March-2009. Since Date1 is not a leap year, the date 29-Feb is not counted. But the same formula with Date1 = 1-Feb-2008 returns 29, since Date1 is a leap year and therefore the date 29-Feb is counted.

---

The simple fact that DATEDIF was implemented to provide compatibility for 1-2-3 workbooks, and that the 1-2-3 engineers took many shortcuts in favor of a small footprint despite funky functionality, and that the Excel engineers did their best to simulate that funkiness, should lead one to avoid it if following best practices. Microsoft would prefer that the function just go away but keep supporting it in half-baked ways because not doing so would cause many more problems.

And it's easy to do the math correctly with relatively simple math formulas without using DATEDIF.

Kevin

And it's easy to do the math correctly with relatively simple math formulas without using DATEDIF.

Kevin