|
by TheExcelAddict.com Calculate The Number Of Days, Months Or Years Between Two DatesHave 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:
=DATEDIF(A1,A2,"y") & " years, " & DATEDIF(A1,A2,"ym") & " months, " & DATEDIF(A1,A2,"md") & " days"
|