Excel DATEDIF to calculate date difference in days, weeks, months or years

In this tutorial, you will find a simple explanation of the Excel DATEDIF function and a few formula examples that demonstrate how to compare dates and calculate the difference in days, weeks, months or years.

Over the past few weeks, we investigated nearly every aspect of working with dates and times in Excel. If you have been following our blog series, you already know how to insert and format dates in your worksheets, how to calculate weekdays, weeks, months and years as well as add and subtract dates.

In this tutorial, we will focus on calculating date difference in Excel and you will learn different ways to count the number of days, weeks, months and years between two dates.

Excel DATEDIF function - get date difference

As its name suggests, the DATEDIF function is purposed for calculating the difference between two dates.

DATEDIF is one of very few undocumented functions in Excel, and because it is "hidden" you won't find it on the Formula tab, nor will you get any hint on which arguments to enter when you start typing the function's name in the formula bar. That is why it's important to know the complete syntax of Excel DATEDIF to be able to use it in your formulas.

Excel DATEDIF function - syntax

The syntax of the Excel DATEDIF function is as follows:

DATEDIF(start_date, end_date, unit)

All three arguments are required:

Start_date - the initial date of the period you want to calculate.

End_date - the ending date of the period.

Unit - the time unit to use when calculating the difference between two dates. By supplying different units, you can get the DATEDIF function to return the date difference in days, months or years. Overall, 6 units are available, which are described in the following table.

Unit Meaning Explanation
Y Years Number of complete years between the start and end dates.
M Months Number of complete months between the dates.
D Days Number of days between the start date and end date.
MD Days excluding years and months The date difference in days, ignoring months and years.
YD Days excluding years The date difference in days, ignoring years.
YM Months excluding days and years The date difference in months, ignoring days and years.

Excel DATEDIF formula

To get the difference between two dates in Excel, your main job is to supply the start and end dates to the DATEDIF function. This can be done in various ways, provided that Excel can understand and correctly interpret the supplied dates.

Cell references

The easiest way to make a DATEDIF formula in Excel is to input two valid dates in separate cells and refer to those cells. For example, the following formula counts the number of days between the dates in cells A1 and B1:

=DATEDIF(A1, B1, "d")

Text strings

Excel understands dates in many text formats such as "1-Jan-2023", "1/1/2023", "January 1, 2023", etc. The dates as text strings enclosed in quotation marks can be typed directly in a formula's arguments. For instance, this is how you can calculates the number of months between the specified dates:

=DATEDIF("1/1/2023", "12/31/2025", "m")

Serial numbers

Since Microsoft Excel stores each date as a serial number beginning with January 1, 1900, you use numbers corresponding to the dates. Although supported, this method is not reliable because date numbering varies on different computer systems. In the 1900 date system, you can use the below formula to find the number of years between two dates, 1-Jan-2023 and 31-Dec-2025:

=DATEDIF(44927, 46022, "y")

Results of other functions

To find out how many days there are between today and 20 May, 2025, this is the formula to use.

=DATEDIF(TODAY(), "5/20/2025", "d")

DATEDIF function in Excel

Note. In your formulas, the end date must always be greater than the start date, otherwise the Excel DATEDIF function returns the #NUM! error.

Hopefully, the above information has been helpful to understand the basics. And now, let's see how you can use the Excel DATEDIF function to compare dates in your worksheets and return the difference.

How to get the number of days between two dates in Excel

If you observed DATEDIF's arguments carefully, you've noticed that there exist 3 different units for counting days between the dates. Which one to use depends on exactly what your needs are.

Example 1. Excel DATEDIF formula to calculate date difference in days

Supposing you have the start date in cell A2 and the end date in cell B2 and you want Excel to return the date difference in days. A simple DATEDIF formula works just fine:

=DATEDIF(A2, B2, "d")

Provided that a value in the start_date argument is less than in end_date. In case the start date is greater than the end date, the Excel DATEDIF function returns the #NUM error, as in row 5:

Counting the number of days between two dates

If you are looking for a formula that can return the date difference in days as either a positive or negative number, simply subtract one date directly from the other:

=B2-A2

Please see How to subtract dates in Excel for full details and more formula examples.

Example 2. Count days in Excel ignoring years

Supposing you have two lists of dates that belong to different years and you wish to calculate the number of days between the dates as if they were of the same year. To do this, use a DATEDIF formula with "YD" unit:

=DATEDIF(A2, B2, "yd")
Excel DATEDIF formula to count days between two dates ignoring years

If you want the Excel DATEDIF function to ignore not only years but also moths, then use the "md" unit. In this case, your formula will calculate days between two dates as if they were of the same month and the same year:

=DATEDIF(A2, B2, "md")

The screenshot below demonstrates the results, and comparing it with the screenshot above can help understand the difference better.
DATEDIF formula to calculate days between two dates ignoring years and months

Tip. To get the number of working days between two dates, use the NETWORKDAYS or NETWORKDAYS.INTL function.

How to calculate date difference in weeks

As you probably noticed, the Excel DATEDIF function does not have a special unit to calculate date difference in weeks. However, there is an easy workaround.

To find out how many weeks there are between two dates, you can use the DATEDIF function with "D" unit to return the difference in days, and then divide the result by 7.

Calculating date difference in weeks in Excel

To get the number of full weeks between the dates, wrap your DATEDIF formula in the ROUNDDOWN function, which always rounds the number towards zero:

=ROUNDDOWN((DATEDIF(A2, B2, "d") / 7), 0)

Where A2 is the start date and B2 is the end date of the period you are calculating.
Calculating how many full weeks there are between two dates

How to calculate the number of months between two dates in Excel

Similarly to counting days, the Excel DATEDIF function can compute the number of months between two dates that you specify. Depending on the unit you supply, the formula will produce different results.

Example 1. Calculate complete months between two dates (DATEDIF)

To count the number of whole months between the dates, you use the DATEDIF function with "M" unit. For example, the following formula compares the dates in A2 (start date) and B2 (end date) and returns the difference in months:

=DATEDIF(A2, B2, "m")

Note. For the DATEDIF formula to calculate months correctly, the end date should always be greater than the start date; otherwise the formula returns the #NUM error.

DATEDIF formula to calculate months between two dates

To avoid such errors, you may force Excel to always perceive an older date as the start date, and a more recent date as the end date. To do this, add a simple logical test:

=IF(B2>A2, DATEDIF(A2,B2,"m"), DATEDIF(B2,A2,"m"))

Example 2. Get the number of months between two dates ignoring years (DATEDIF)

To count the number of months between the dates as if they were of the same year, type "YM" in the unit argument:

=DATEDIF(A2, B2, "ym")
Calculating months between two dates ignoring years

As you see, this formula also returns an error in row 6 where end date is less than the start date. If your data set may contain such dates, you will find the solution in the next examples.

Example 3. Calculating months between two dates (MONTH function)

An alternative way to calculate the number of months between two dates in Excel is using the MONTH function, or more precisely a combination of MONTH and YEAR functions:

=(YEAR(B2) - YEAR(A2))*12 + MONTH(B2) - MONTH(A2)

Of course, this formula is not so transparent as DATEDIF and it does take time to wrap your head around the logic. But unlike the DATEDIF function, it can compare any two dates and return the difference in months as either a positive or negative value:
Calculating months between two dates using the MONTH and YEAR functions

Notice that the YEAR/MONTH formula has no problem with calculating months in row 6 where the start date is more recent than the end date, the scenario in which an analogues DATEDIF formula fails.

Note. The results returned by DATEDIF and YEAR/MONTH formulas are not always identical because they operate based on different principles. The Excel DATEDIF function returns the number of complete calendar months between the dates, while the YEAR/MONTH formula operates on months' numbers.

For example, in row 7 in the screenshot above, the DATEDIF formula returns 0 because a complete calendar month between the dates has not elapsed yet, while YEAR/MONTH returns 1 because the dates belong to different months.

Example 4. Counting months between 2 dates ignoring years (MONTH function)

In case all of your dates are of the same year, or you want to calculate months between the dates ignoring years, you can the MONTH function to retrieve the month from each date, and then subtract one month from the other:

=MONTH(B2) - MONTH(A2)

This formula works similarly to Excel DATEDIF with "YM" unit as demonstrated in the following screenshot:
Counting months between 2 dates ignoring years with MONTH function

However, the results returned by two formulas differ is a couple of rows:

  • Row 4: the end date is less than the start date and therefore DATEDIF returns an error while MONTH-MONTH yields a negative value.
  • Row 6: the dates are of different months, but the actual date difference is just one day. DATEDIF returns 0 because it calculates whole months between 2 dates. MONTH-MONTH returns 1 because it subtracts the months' numbers from each other ignoring days and years.

How to calculate years between two dates in Excel

If you followed the previous examples where we calculated months and days between two dates, then you can easily derive a formula to calculate years in Excel. The following examples can help you check if you got the formula right :)

Example 1. Calculating complete years between two dates (DATEDIF function)

To find out the number of complete calendar years between two dates, use the old good DATEDIF with the "Y" unit:

=DATEDIF(A2,B2,"y")

DATEDIF function to calculate complete years between two dates

Notice that the DATEDIF formula returns 0 in row 6, although the dates are of different years. This is because the number of full calendar years between the start and end dates equals to zero. And I believe you are not surprised to see the #NUM! error in row 7 where the start date is more recent than the end date.

Example 2. Calculating years between two dates (YEAR function)

An alternative way to calculate years in Excel is using the YEAR function. Similarly to the MONTH formula, you extract the year from each date, and then subtract the years from each other:

=YEAR(B2) - YEAR(A2)

In the following screenshot, you can compare the results returned by the DATEDIF and YEAR functions:
Calculating years between two dates using the YEAR function

In most cases the results are identical, except that:

  • The DATEDIF function calculates complete calendar years, while the YEAR formula simply subtracts one year from the other. Row 6 illustrates the difference.
  • The DATEDIF formula returns an error if the start date is greater than the end date, while the YEAR function returns a negative value, as in row 7.

How to get date difference in days, months and years

To count the number of complete years, months and days between two dates in a single formula, you simply concatenate three DATEDIF functions:

=DATEDIF(A2, B2, "y") &" years, "&DATEDIF(A2, B2, "ym") &" months, " &DATEDIF(A2, B2, "md") &" days"
Calculating date difference is days, months and years

If you'd rather not display zero values, you can wrap each DATEDIF in the IF function as follows:

=IF(DATEDIF(A2,B2,"y")=0, "", DATEDIF(A2,B2,"y") & " years ") & IF(DATEDIF(A2,B2,"ym")=0,"", DATEDIF(A2,B2,"ym") & " months ") & IF(DATEDIF(A2, B2, "md")=0, "", DATEDIF(A2, B2, "md") & " days"

The formula displays only non-zero elements as demonstrated in the following screenshot:
Calculate date difference is days, months and years ignoring zero values

For other ways to get date difference in days, see How to calculate days since or until date in Excel.

DATEDIF formulas to calculate age in Excel

In fact, calculating someone's age based on the date of birth is a special case of calculating date difference in Excel, where the end date is today's date. So, you use a usual DATEDIF formula with "Y" unit that returns the number of years between the dates, and enter the TODAY() function in the end_date argument:

=DATEDIF(A2, TODAY(), "y")

Where A2 is the birth date.

The above formula calculates the number of complete years. If you'd rather get the exact age, including years, months and days, then concatenate three DATEDIF functions like we did in the previous example:

=DATEDIF(B2,TODAY(),"y") & " Years, " & DATEDIF(B2,TODAY(),"ym") & " Months, " & DATEDIF(B2,TODAY(),"md") & " Days"

And you will get the following result:
DATEDIF formula to calculate age in Excel

To learn other methods of converting a birthdate to age, check out How to calculate age from date of birth.

Date & Time Wizard - easy way to build date difference formulas in Excel

As demonstrated in the first part of this tutorial, Excel DATEDIF is quite a versatile function suitable for a variety of different uses. However, there is one significant drawback - it is undocumented by Microsoft, meaning, you won't find DATEDIF in the list of functions nor will you see any argument tooltips when you start typing a formula in a cell. To be able to use the DATEDIF function in your worksheets, you have to remember its syntax and enter all the arguments manually, which might be a time-consuming and error-prone way, especially for beginners.

Ultimate Suite for Excel changes this radically as it now provides the Date & Time Wizard that can make almost any date difference formula in no time. Here's how:

  1. Select the cell where you want to insert the formula.
  2. Go to the Ablebits Tools tab > Date & Time group, and click the Date & Time Wizard button:
    Date & Time Wizard for Excel
  3. The Date & Time Wizard dialog window shows up, you switch to the Difference tab and supply data for the formula arguments:
    • Click in the Date 1 box (or click the Collapse Dialog button to the right of the box) and select a cell containing the first date.
    • Click in the Date 2 box and select a cell with the second date.
    • Select the desired unit or combination of units from the Difference in drop-down menu. As you do this, the wizard lets you preview the result in the box and the formula in the cell.
    • If you are happy with the preview, click the Insert formula button, otherwise try different units.

For example, this is how you can get the number of days between two dates in Excel:
Getting the number of days between two dates

Once the formula is inserted in the selected cell, you can copy it to other cells as usual by double-clicking or dragging the fill handle. The result will look similar to this:
The formula to calculate the difference between two dates in days

To present the results in the most suitable way, a few more additional options are available:

  • Exclude years and/or exclude months from calculations.
  • Show or do not show text labels like days, months, weeks, and years.
  • Show or do not show zero units.
  • Return the results as negative values if Date 1 (start date) is greater than Date 2 (end date).

As an example, let's get the difference between two dates in years, months, weeks and days, ignoring zero units:

The formula to calculate date difference in years, months, weeks and days.

Benefits of using Date & Time Formula Wizard

Apart from speed and simplicity, the Date & Time Wizard provides a few more advantages:

  • Unlike a regular DATEDIF formula, an advanced formula created by the wizard does not care which of the two dates is smaller and which is larger. The difference is always calculated perfectly even if Date 1 (start date) is greater than Date 2 (end date).
  • The wizard supports all possible units (days, weeks, months and years) and lets you choose from 11 different combinations of these units.
  • The formulas the wizard builds for you are normal Excel formulas, so you are free to edit, copy or move them as usual. You can also share your worksheets with other people, and all formulas will remain in place, even if someone does not have the Ultimate Suite in their Excel.

This is how you compute the difference between two dates in various time intervals. Hopefully, the DATEDIF function and other formulas you've learned today will prove useful in your work.

Available downloads

Ultimate Suite 14-day fully-functional version (.exe file)

292 comments

  1. Hi

    I want to know the formula which will just give year and month where month is not in 2 decimal. Here is the formula which I have used =DATEDIF(E7,TODAY(),"Y")& "."&" "&DATEDIF(E7,TODAY(),"YM")

    and result is 0.10 which is 10 months, with this result I am not able to filter the file in chronological order.

    Is there a way to resolve this problem.

  2. Hi,

    I want to know which formula I have to use if I want to calculate no. of days before a specific date, and total no. of days after or from specific date

    for ex: if am calculating number of sick leave days for employee per year and different period of sick leave given.

    Regards

  3. How to convert "2 years 10 months" into number of days

  4. Hi
    Svetlana

    Thank you, but I do not have good English helped me to formula

    =IF(DATEDIF(A2,B2,"y")=0, "", DATEDIF(A2,B2,"y") & " years ") & IF(DATEDIF(A2,B2,"ym")=0,"", DATEDIF(A2,B2,"ym") & " months ") & IF(DATEDIF(A2, B2, "md")=0, "", DATEDIF(A2, B2, "md") & " days"

    Thank you,Thank you

  5. I am not great at using Excel, so I apologize if this question seems a little basic, but I need help. I have a spreadsheet that has two columns of dates. I would like to use datedif to automatically calculate the difference between these sets of dates into a third column without having to type the formula into each cell. Is there a way to do this?

    • Hello Torey,

      Of course, you don't have to type the formula in each cell manually. Just write the DATEDIF formula for the top cell using relative cell references (without the $ sign, like A1). Then double click a small square at the lower right-hand corner of the formula cell (it will change to the plus sign as soon as you hover over it), and the formula will copy across the entire column.

      You can find a handful of other ways to copy formulas in Excel here: How to copy a formula in Excel.

  6. Hi,

    I am trying to find the chronological age in years and months between a birthday and a testing date.

    For example:
    Birth Date: 3-3-2001
    Test Date: 6-29-2007
    Then the age would be: 6 years 3 months

    Birth Date: 8-2-1999
    Test Date: 5-8-2006
    Then the age would be: 7 years 9 months

    Birth Date: 11-24-1985
    Test Date: 8-13-2006
    Then the age would be: 21 years 8 months

    Is this possible? Thanks so much!

  7. Hello Svetlana,
    Please could you assist me in my below calculation because I am struggling 20 hours and cannot get it using many formulas.
    I have this formula : Cell D44 03:15:30 (where dd:hh:mm) - Cell D45 00:10:52 (where dd:hh:mm). I want to get the result in the cell D46, in case that D45 is greater then appears ####### I tried many solution but they didn't work.
    Additional, when I form the cell D46 with different colour based on the result then when I close the Worksheet and re-open it again the colour hasn't remained as I formed. I don't want to use the form 1904, I used it but the dates were not those I wanted to get. I used Excel 2011 in Mac computer.
    Thanks a lot in advance.

  8. Hello Svetlana,

    Can you Please help me out with this: I need to calculate number of working years, months and days between two dates with break.
    EX: If few employee start working at one date and working certain period then left company and after few years comeback. With DATEDIF function using SUM function getting wrong result.
    Please let me know if it is possible and if it is kindly let me know how.

  9. I have a spreadsheet that provides the date of when an business item is received for processing. And a second column for a date when the item is submitted for processing. I would like a third column that highlights each item where the difference between receipt and submission is greater than 3 working days. Thank you for your assistance.

  10. If the second date is empty and I want the value to remain blank or say not complete how do I set that up. I am getting #value

    • Hi Alex,

      You can use the IF function to check for blank cells, like this:

      =IF(AND(A1<>"", B1<>""), DATEDIF(A1,B1,"d"), "")

      or

      =IF(AND(A1<>"", B1<>""), DATEDIF(A1,B1,"d"), "not complete")

  11. Can you Please help me out with the following problem.I need to get two values from two different cells and combine it in one cell with certain preexisting characters.
    Ex: Cell A1 contains "Aakash" Cell A2 contains "D V". I need final expression in cell A3 as "UI-Aakash D V". Please let me know if it is possible and if it is kindly let me know how.

  12. I'm trying to calculate the number of days a task is overdue. C2 contains the date the assignment is due and d2 is the date the assignment was completed. Example:

    Assignment Due Date Assignment Completion Date Days Overdue
    5/9/2016 5/2/2016 0
    5/10/2016 5/13/2016 3

    I need to be able to calculate the number of days overdue. What formula do I use? I know I can't use the DATEIF formula. Thank you for your help.

  13. I have simple formula to calculate number of days between dates =DAYS(G266,C266). If there is no date yet in G column the result in the H column with the formula is -42412 or #VALUE!. What formula in the H column cell blank when there is no date yet entered?
    Thanks!

  14. HI
    IN CONDITIONAL PARAMETER

    01 APRIL 2015 TO 30 JUNE 2015 = IS 1ST QTR
    01 JULY 2015 TO 30 SEPTEMBER 2015 = IS 2ND QTR

    01 OCTOBER 2015 TO 30 DECEMBER 2015 = IS 3RD QTR

    01 JANUARY 2015 TO 30 MARCH 2015 = IS 4TH QTR

    IF WE PUT THE DATE AS WE DESIRE IT WILL AUTOMETIC PRINT/DISPLAY IT QTR

  15. Hi Svetlana

    Could you please help me with the formula.
    I have used data validation. All I want is if it says says. I want a date to be populated after 7 business days. If no I want the date after 5 business days to be populated in a cell.

  16. how are you,may you pliz send me a worked downloadable example on hw to calculate days between two dates.

  17. I have a question... that kind of go along these lines...

    I have my formula: =DATEDIF(D3,TODAY(),"D")

    This is giving me the aging that I desire...

    The problem is, I want to be able to keep this aging... but I also want to stop the counter, when I plug in a completion date... of a given task...

    Any thoughts~

    • Hi Shay,

      I think you can use a formula similar to this:
      =IF(E3<>"", DATEDIF(D3,E3,"d"), DATEDIF(D3,TODAY(),"d"))

      Where E3 is the completion date. If there is a date in E3, the formula calculates the difference between D3 and E3, otherwise between D3 and today's date.

  18. Hi Svetlana,

    kindly help, i put different date in one column i need the date to date between days
    For example Column A i give different date 1 to 10 cell now i need column B the different date to date days
    Column A Column B
    11-May-16
    13-May-16 ?days
    17-May-16 ?days
    1-Jun-16 ?days

  19. I am using this formula and the result is not correct. For example, I'm calculating the number of months between 3/26/2013 - 1/30-2016, which is logically 2.10. I use the formula =ROUND((DATEDIF(G2,J2,"M")/12), 1)and the result is 2.8. The cell G2 contains the date 3/26/2013 and J2 contains the date 1/30/2016. Where did I go wrong?

  20. 5/25/2016 -8/31/2017 if between these two dates i want to find no of days in may then june and so respectively how do i do that. for example in may the number of days are 5 . i want the formula for this.

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)