Excel: Average Number of Years, Months, and Days Between Dates

Last reviewed: June 27, 1997
Article ID: Q51309

SUMMARY

The following Microsoft Excel function macro calculates the average number of years, months, and days between a list of start and end dates.

To use this macro, enter the following macro commands into an Excel macro sheet:

 +---+----------------------------------------------------------------+
 |   |                                A                               |
 +---+----------------------------------------------------------------+
 | 1 | aveymd                                                         |
 +---+----------------------------------------------------------------+
 | 2 | =ARGUMENT("start",64)                                          |
 +---+----------------------------------------------------------------+
 | 3 | =ARGUMENT("end",64)                                            |
 +---+----------------------------------------------------------------+
 |   | =ROUND(AVERAGE(YEAR(end)-YEAR(start)-IF((MONTH(end)            |
 | 4 |  <MONTH(start))+(MONTH(end)=MONTH(start))*(DAY(end)            |
 |   |  <DAY(start)),1)),1)&"y "                                      |
 +---+----------------------------------------------------------------+
 | 5 | =ROUND(AVERAGE(MONTH(end)-MONTH(start)+(MONTH(end)             |
 |   |  <MONTH(start))*12-(DAY(end)<DAY(start))),0)&"m "              |
 +---+----------------------------------------------------------------+
 | 6 | =ROUND(AVERAGE(end-DATE(YEAR(end),MONTH(end)-(DAY(end)         |
 |   |  <DAY(start)),DAY(start))),0)&"d"                              |
 +---+----------------------------------------------------------------+
 | 7 | =RETURN(A4&A5&A6)                                              |
 +---+----------------------------------------------------------------+

Note: The formulas in A4, A5, and A6 must be "COMMAND+ENTERed" (instead of pressing RETURN on the main keyboard after typing the formula, hold down the COMMAND key and press the ENTER key on the numeric keypad).

Define the commands as a function macro:

  1. Select cell A1 (the cell containing "aveymd").

  2. From the Formula menu, choose Define Name.

  3. Under Macro, select Function.

  4. Click OK.

To use the macro, choose Paste Function from the Formula menu and select the macro from the list (it will appear close to or at the bottom). Type in the cell references of the start and end date arrays, respectively, separated by a comma.

For example, if the start dates are in cells A2:A10 and the end dates are in cells B2:B10, the formula is

   =Macro1!aveymd(A2:A10,B2:B10)

where "Macro1" is the name of the macro sheet containing the macro.


Additional query words: 1.00 1.03 1.04 1.06 1.50 2.20 3.00


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 27, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.