"How To Excel" Mini-Tutorials
by TheExcelAddict.com
"Helping Average Spreadsheet Users Become Local Spreadsheet Experts"

Calculate The Number Of Days, Months Or Years Between Two Dates

Have you ever needed to determine the number of days, months or years between two dates? Calculating the number of days using Excel is pretty simple. Just use a formula to subtract the later date from the earlier date.

For example, if cell A1 contains 1-Jan-2004 and cell A2 contains 03-Mar-2004, you simply enter the formula =A2-A1 in cell A3 to get the number of days. At first the result may look strange. That's because Excel assumed you were entering another date and automatically formatted cell A3 as a date. To fix that, go to the Format menu, select Cells, click the Number tab and select General from the Category list. Your answer should be 62.

However, calculating the number of months or years between two dates isn't so obvious. There's a Function in Excel that makes this task easy but for some reason Microsoft has hidden it away. You won't find it in the Paste Functions list (Insert, Functions). The function is called DATEDIF (i.e. date difference).

Let's use the same dates as above. The syntax for the function is


Our formula to calculate the number of complete months between the two dates would be


Similarly, the formula to calculate the number of complete years is =DATEDIF(A1,A2,"y"), although in our example it would yield 0 complete years. Change cell A1 to a date a year or more earlier and you'll see the result.

A couple of things to keep in mind about the DATEDIF function:

  1. The start date must be less than or equal to the end date, otherwise it will give an error.
  2. Acceptable interval codes are "d", "m", "y", "ym", "yd", "md" (with quotes)
  3. It may appear obvious what the "ym", "yd", and "md" interval codes do but they require a second look. The "ym" interval code yields the number of months between the two dates as if they were in the same year and ignores the year. The "yd", and "md" interval codes yields the number of days between the two dates as if they were in the same year and ignores the year.
To calculate the number of years, months and days between two dates (more than a year apart) you can use this formula (assuming your start date is in cell A1 and your end date is in cell A2).
=DATEDIF(A1,A2,"y") & " years, " & DATEDIF(A1,A2,"ym") & " months, " & DATEDIF(A1,A2,"md") & " days"
(Highlight and copy this formula from here, paste into the Excel formula bar, and adjust the cell references)

Get my FREE
Excel Tips

Subscribe now to 'Spreadsheet Tips From An Excel Addict' and start receiving these time-saving Excel tips

Check your email in a few minutes. You will need to click on the confirmation link before you begin receiving the tips

If you came to this page from my Excel Mini-Tutorials page, click here to close this window,
otherwise click here and you'll find lots more time-saving Excel tutorials like this one.