# Calculating date differences in Excel using DATEDIF

If you work with Excel spreadsheets, you’ve likely ended up with the need to compare two dates to find the number of days, months, or years between them. Using the DATEDIF function, you can easily accomplish that.

Here’s a spreadsheet that has two dates in cells A2 and B2. Using the DATEDIF function, we get the year difference (cell C2), the month difference (cell D2), and day difference (cell E2): To calculate the year difference, we create the formula =DATEDIF(A2, B2, “Y”), where A2 and B2 are the dates, and “Y” says to calculate the year difference: To calculate the month difference, we create the formula =DATEDIF(A2, B2, “M”), where A2 and B2 are the dates, and “M” says to calculate the month difference: To calculate the day difference, we create the formula =DATEDIF(A2, B2, “D”), where A2 and B2 are the dates, and “D” says to calculate the day difference: In cell F2, we also show how you can just subtract one date from another to get the difference in days by using a formula of =B2-A2: 