There is a number of ways for calculating the difference between two dates in Excel. You may get the number of days, months and years by using these ways along with adding or subtracting and getting the resultant dates.
First way – Subtract Dates in Excel
This is the simplest way of subtracting two dates and getting the number of days. Simply use the minus “-“ between two dates as shown in the example below.
For the example, the A2 and B2 cells are given dates. The C2 column displays the subtracted result of these two dates.
The different between 5/30/2016 and 6/6/2016 is 7 days.
Just make sure that the C2 column or cell wherever you are displaying the result after subtraction is using the general format (and not date format). See the graphic below where you may ensure it:
You can see this dropdown under the Home in the ribbon.
Using DATE function to subtract Years/Months and Days
In this example, you may enter a date in the D3 cell and DATE formula will subtract 2 years, minus 2 months and minus 2 days from that date and display the resultant date in D4 cell. First, have a look at the formula and result and I will explain a little:
=DATE(YEAR(E3) – 2, MONTH(E3) – 2, DAY(E3) – 2 )
The output as I entered 3 March 2017 (3/3/2017):
In the formula, I used YEAR, MONTH and DAY functions inside the DATE function. The DAY function got the day from the given E2 cell date and subtracted 2. The MONTH function took the March from the given date and subtracted 2 months. Similarly, the YEAR function subtracted 2 years.
At the end, the DATE function combined all three and resulted in 1/1/2015.
Add date in Excel formula
In the same way, you may add days, numbers and years in the given date by using this formula:
=DATE(YEAR(E3) + 2, MONTH(E3) + 2, DAY(E3) + 2 )
See what it resulted from the same date as I used ‘+’ for addition:
The example of subtracting given date with today
You may use the TODAY() function for getting the difference between current day and a given day e.g. Date of Birth. See the following example of subtracting TODAY() by DOB by using “-“:
The date subtract Formula:
Using DATEDIF function for getting the difference of days
You may also use DATEDIF function for the difference between two dates. For that, use the “D” value for the unit in DATEDIF function. If you have no idea about the DATEDIF function, the following example should make it clear:
The DATEDIF formula:
The DATEDIF function takes two dates. The first date should be less than the second date. The third argument specifies what you require; days, months or years?
Getting the Month difference example
The following example shows getting the difference in Months for the two given dates. This is done by using the DATEDIF function with “M” value:
Make sure using the respective cells containing dates as you copy this formula.
The example of TODAY() minus DOB for getting age in Years
For this example, the number of years is calculated after subtracting the TODAY()’s date by DOB column. This is accomplished by using the “Y” unit value in DATEDIF function as follows:
The output as used with few cells:
Getting years difference by simply subtracting two dates
You may also get the years difference by using the first way in this tutorial i.e. simply use the subtraction “-“. In that case, two dates are subtracted and the result is divided by 365 or 365.25 (for leap years factor). Have a look at this formula and output:
The formula for years calculation with subtraction:
The resultant sheet:
In the C2 and C3 cells, you may notice the years with decimal points. For getting the rounded years, you may use the ROUND function as used for C4 cell:
Alternatively, you may also use the INT function that I applied in C5 and C6 cells:
Getting the date difference with Years/Months and Days combined
Until now, we have seen examples of getting the Years, months and days separately. In situations, you may require all. See the following example where the difference of dates is returned for: Days, months and years for the DOB:
The formula used in C5 cell:
1 =DATEDIF(A5,TODAY(),"y") &" Years and "&DATEDIF(A5,TODAY(),"ym") &" Month(s) and " &DATEDIF(A5,TODAY(),"md") &" Days"
The overall output:
You may learn more about DATEDIF function in its tutorial.