- MS Excel provides a number of ways to calculate the difference between two dates.
- 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 by (-) operator
This is the simplest way of subtracting two dates and getting the number of days. Simply use the minus “-“ between two dates.
For example, the A2 and B2 cells are given dates. The C2 cell displays the subtracted result of these two dates.
The difference 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 the date format). See the graphic below where you may ensure it:
You can see this dropdown under the Home in the ribbon.
Second way: Using the 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 the 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 March from the given date and subtracted 2 months. Similarly, the YEAR function subtracted 2 years.
In the end, the DATE function combined all three and resulted in 1/1/2015.
Add a date in Excel formula
In the same way, you may add days, numbers, and years to the given date by using this formula:
=DATE(YEAR(E3) + 2, MONTH(E3) + 2, DAY(E3) + 2 )
See what that resulted from the same date as I used '+' for addition:
The example of subtracting a given date from today
You may use the TODAY() function to get the difference between the 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:
Also learn: Excel Today's Date by using VBA
Third way: Using DATEDIF function to get the difference in days
If you have no idea about the DATEDIF function, the following example should make it clear:
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 the difference in Months for the two given dates. This is done by using the DATEDIF function with “M” value:
Make sure to use 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 from the DOB column. This is accomplished by using the “Y” unit value in DATEDIF function as follows:
The output as used with few cells to calculate age in years in Excel:
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 the 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:
=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.