Friday, May 25, 2012

DATEDIF Function in Excel

DATEDIF  function calculates the difference between two dates and expresses the result in terms of months, days or years. Even though it is very useful function Excel, there is no documentation in excel help documentation.  This tip will show you how to use DATEDIF function.
DATEDIF function syntax:
=DATEDIF(date1,date2,interval)
Date 1 and Date 2 are standard dates or a reference to a cell that contains a date. Date 1 should be earlier than  or equal to Date 2. Third argument Interval is a text string that specifies the unit of time that will be returned.
Various valid interval codes are as follows:
m: The number of complete months between two dates Date1 and Date2
d: The number of days between two dates Date 1 and Date 2
y: The number of complete years between Date 1 and Date 2
ym: The number of months between Date 1 and Date 2. This interval excludes years. So it works as though the two dates are in the same year.
yd: The number of days between Date 1 and Date 2. This interval excludes years. So it works as though the two dates are in the same year.
md: The number of days between Date 1 and Date 2. This interval excludes both year and month.  So it works as though Date 1 and Date 2 are in same month and the same year.

Example for DATEDIF functions: Below is the sample excel sheet with two dates

Formula used here are:

=DATEDIF(A2,B2,"m") which return 73
=DATEDIF(A3,B3,"d") which return 2226
=DATEDIF(A4,B4,"y") which returns 6
=DATEDIF(A5,B5,"ym") which returns 1
=DATEDIF(A6,B6,"yd") which returns 34
=DATEDIF(A7,B7,"md") which returns 4.
This formula works on Excel 2000, Excel XP, Excel 2003, Excel 2007 and Excel 2010 without any extra addons.

No comments:

Post a Comment