Beruflich Dokumente
Kultur Dokumente
ExcelDATEDIFFunctionCalculatethedifferencebetweentwodates
HOME
HOW TOS
INTERESTING
EXCEL FORMULAS
EXCEL CHARTS
VBA IN EXCEL
OTHERS
DATEDIF is a hidden function in Excel. As the name suggests the job of this function is to calcula
difference between two given dates.
I have referred this function as hidden because, for some reason Microsoft has decided not to d
function. And because of this you wont find this function in the Formula Tab.
To verify this, try and type =DATE in any cell. You will see, Excel enlists all the functions that star
word date but it doesnt shows DATEDIF.
Please note that, DATEDIF Function in Excel is totally different from the DATEDIFF (Notice the e
Function in VBA.
Learning the syntax of DATEDIF function is very important. Because for applying this function y
know its complete syntax as Excel wont provide you any help on this.
The Syntax of DATEDIF function is as follows:
http://www.exceltrick.com/formulas_macros/exceldatediffunction/
1/11
2/25/2015
ExcelDATEDIFFunctionCalculatethedifferencebetweentwodates
=DATEDIF(Start_Date,End_Date,Unit)
Here, Start_Date is the starting date of the period that you wish to calculate. Start_Date
as a string within double quotes (like: 10/10/2013), it can also be entered as a serial number, a
internally treats dates as serial numbers (for example: the number 41557 represents 10/10/2013
using the 1900 date system), or you can also supply the dates as a formula (like: =DATE(2013,10,
End_Date is the last date of the period that you wish to calculate. Similar to Start_Date,
also be entered as a string, number or a formula.
Unit specifies the interval by which you want the difference to be returned. There are 6 Units
described as under:
UNIT
RETURNS
MD
Returns the difference between the days in Start_Date and End_Date. Here the months and years o
are ignored.
YM
Returns the difference between the months in Start_Date and End_Date. Here the days and years o
are ignored
YD
Returns the difference between the days of Start_Date and End_Date. Here the years of the dates a
http://www.exceltrick.com/formulas_macros/exceldatediffunction/
2/11
2/25/2015
ExcelDATEDIFFunctionCalculatethedifferencebetweentwodates
End_Date: End_Date will be todays date. So, instead of entering the todays date manually we
Today() function.
Unit: As we want to find the number of days between the period. So, the Unit will be d.
3/11
2/25/2015
ExcelDATEDIFFunctionCalculatethedifferencebetweentwodates
Example 2: Write a formula to calculate the number of complete months from 1/1/2001 to 1/1/2
The formula that we are going to user here is:
=DATEDIF("01/01/2001","01/01/2007","m")
http://www.exceltrick.com/formulas_macros/exceldatediffunction/
4/11
2/25/2015
ExcelDATEDIFFunctionCalculatethedifferencebetweentwodates
Example 3: Write a formula to calculate your age in years, months and days.
For finding the age we will need birth date of a person. In our example we will take the birth dat
12/12/1986
So, we will use a formula =DATEDIF("12/12/1986",TODAY(),"y")&"years,"&
DATEDIF("12/12/1986",TODAY(),"ym")&"month(s),"&DATEDIF("12/12/1986",TODAY(),"
Days"
In Example 3 we have seen how DATEDIF function can be used of calculating age. However, if th
years and/or months is 0, then the resultant of the formula looks strange.
Okay, I will try to explain this in detail.
Consider that we have to calculate age of a baby born on 12/12/2012.
So, will try to use the formula: =DATEDIF("12/12/2012",TODAY(),"y")&"years,"&
DATEDIF("12/12/2012",TODAY(),"ym")&"month(s),"&DATEDIF("12/12/2012",TODAY(),"
Days"
http://www.exceltrick.com/formulas_macros/exceldatediffunction/
5/11
2/25/2015
ExcelDATEDIFFunctionCalculatethedifferencebetweentwodates
=IF(DATEDIF("12/12/2012",TODAY(),"y")=0,"",DATEDIF("12/12/2012",TODAY(),"y")
years,")&IF(DATEDIF("12/12/2012",TODAY(),"ym")=0,"",DATEDIF("12/12/2012",TOD
&"month(s),")&IF(DATEDIF("12/12/2012",TODAY(),"md")=
0,"",DATEDIF("12/12/2012",TODAY(),"md")&"Days")
http://www.exceltrick.com/formulas_macros/exceldatediffunction/
6/11
2/25/2015
ExcelDATEDIFFunctionCalculatethedifferencebetweentwodates
supressing-zeros-in-datedif-10
I think now you all would agree, that the output of this new formula looks better than the old on
Is DATEDIF a safe function?
I know this is a bit strange but many Excel Gurus say that its not good to use DATEDIF in your i
workbooks. As this is an undocumented function and going forward there may be a chance that
may remove support for this function.
7/11
2/25/2015
ExcelDATEDIFFunctionCalculatethedifferencebetweentwodates
The alternative to Excel DATEDIF would be a User defined function (UDF) that internally uses th
DATEDIFF function:
FunctionxlDATEDIF(Start_DateAsDate,End_DateAsDate,UnitAsString)AsStrin
xlDATEDIF=DateDiff(Unit,Start_Date,End_Date)
EndFunction
This UDF accepts three parameters:
Start_Date: The days from which the period begins.
End_Date: It is the last date of the period that you wish to calculate.
Unit: It specifies the interval by which you want the difference. Here the unit accepts follow
Value Description
YYYY Year
Q
Quarter
Month
Day of year
Day
Weekday
WW
Week
Hour
Minute
Second
Example 4: Using this UDF to find the number of days between 01/01/2010 and 01/01/2012.
To do this we will use the formula:
=xlDATEDIF("01/01/10","01/01/12","d")
http://www.exceltrick.com/formulas_macros/exceldatediffunction/
8/11
2/25/2015
ExcelDATEDIFFunctionCalculatethedifferencebetweentwodates
So, this was all about Excel DATEDIF function. Do let me know in case you come across any issu
using this function.
Ankit is the founder of Excel Trick. He is tech Geek who loves to sit in front of his square head
(his PC) all day long. :D. Ankit has a strong passion for learning Microsoft Excel. His only aim is
guys into 'Excel Geeks'.
You can find Ankit on FaceBook or Google Plus
http://www.exceltrick.com/formulas_macros/exceldatediffunction/
9/11