Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST TOOLS

Excel Tutorial

Excel HOME Excel Introduction Excel Get Started Excel Overview Excel Syntax Excel Ranges Excel Fill Excel Move Cells Excel Add Cells Excel Delete Cells Excel Undo Redo Excel Formulas Excel Relative Reference Excel Absolute Reference Excel Arithmetic Operators Excel Parentheses Excel Functions

Excel Formatting

Excel Formatting Excel Format Painter Excel Format Colors Excel Format Fonts Excel Format Borders Excel Format Numbers Excel Format Grids Excel Format Settings

Excel Data Analysis

Excel Sort Excel Filter Excel Tables Excel Conditional Format Excel Highlight Cell Rules Excel Top Bottom Rules Excel Data Bars Excel Color Scales Excel Icon Sets Excel Manage Rules (CF) Excel Charts

Excel PivotTables

Excel PivotTable Intro Excel Create PivotTable Excel PivotTable Values Excel PivotTable Filter Excel PivotTable Group Excel Calculated Field Excel PivotChart

Excel Case

Case: Poke Mart Case: Poke Mart, Styling

Excel Functions

AND AVERAGE AVERAGEIF AVERAGEIFS CONCAT COUNT COUNTA COUNTBLANK COUNTIF COUNTIFS DATEDIF FILTER HLOOKUP IF IFERROR IFS INDEX INDEX MATCH LEFT LEN LOWER MATCH MAX MEDIAN MID MIN MODE NETWORKDAYS NPV OR PROPER RAND RIGHT ROUND SORT STDEV.P STDEV.S SUBSTITUTE SUM SUMIF SUMIFS SUMPRODUCT TEXTJOIN TODAY TRIM UNIQUE UPPER VLOOKUP XLOOKUP XOR

Excel How To

Convert Time to Seconds Difference Between Times NPV (Net Present Value) Remove Duplicates

Excel Cert

Excel Certificate

Excel Examples

Excel Exercises Excel Syllabus Excel Study Plan Excel Training

Excel References

Excel Keyboard Shortcuts


Excel DATEDIF Function


Share

DATEDIF Function

The DATEDIF function is a premade function in Excel, which calculates the difference between two dates in years, months or days.

It is typed =DATEDIF and has the following parts:

=DATEDIF(start_date, end_date, unit)

Note: DATEDIF is not shown in the list of suggestions when you start typing a function, so you have to type the whole name yourself. It is kept for compatibility with older spreadsheet programs, like Lotus 1-2-3, but it works in all current versions of Excel.

Note: The different parts of the function are separated by a symbol, like comma , or semicolon ;

The symbol depends on your Language Settings.

Start_date: The first date. It must be earlier than, or the same as, the end date.

End_date: The last date. Use TODAY() to count up to today.

Unit: What to count, as text in double quotes. The examples are for 2019-04-01 to 2026-09-28:

UnitReturnsExample
"Y"Complete years7
"M"Complete months89
"D"Days2737
"MD"Days, ignoring months and years27
"YM"Months, ignoring years5
"YD"Days, ignoring years180

Warning: Microsoft recommends that you do not use "MD". In some cases it gives a negative number, zero, or a wrong result.

How to use the DATEDIF function:

  1. Select a cell (C2)
  2. Type =DATEDIF(
  3. Select the start date (B2)
  4. Type (,)
  5. Type or select the end date (DATE(2026,9,28))
  6. Type (,)
  7. Type the unit in double quotes ("Y")
  8. Hit enter

Let's have a look at an example!

The Poke Mart has a club for trainers. This table shows when some trainers became members (example data). Copy it and paste it into cell A1:

Example data

AB
1TrainerMember Since
2Ash2019-04-01
3Misty2021-11-30
4Brock2016-09-28
5Dawn2024-06-15
6Gary2026-02-10

Note: Excel may show the dates in another format, like 4/1/2019, depending on your settings. The results are the same.

Type Years, Months and Days in C1, D1 and E1. Find how long each trainer has been a member, up to 2026-09-28. Type the formulas in C2, D2 and E2, and fill them down to row 6:

ABCDE
1TrainerMember SinceYearsMonthsDays
2Ash2019-04-017892737
3Misty2021-11-304571763
4Brock2016-09-28101203652
5Dawn2024-06-15227835
6Gary2026-02-1007230

The formula in C2:

=DATEDIF(B2, DATE(2026,9,28), "Y")

The formula in D2:

=DATEDIF(B2, DATE(2026,9,28), "M")

The formula in E2:

=DATEDIF(B2, DATE(2026,9,28), "D")

Ash became a member on 2019-04-01. That is 7 complete years, 89 complete months, or 2737 days.

Brock became a member exactly 10 years ago. Misty became a member on 2021-11-30. Her 5th year is not complete until 2026-11-30, so her Years result is 4.

The DATE function makes a date from a year, a month and a day. In your own sheet, use TODAY() instead of DATE(2026,9,28) to count up to the current date. The results then change every day. See TODAY.



Years and Months

To show a length of time like 7 years, 5 months, combine "Y" with "YM". "YM" counts the months that are left after the complete years.

Type Membership in F1. Type this formula in F2 and fill it down to F6:

ABF
1TrainerMember SinceMembership
2Ash2019-04-017 years, 5 months
3Misty2021-11-304 years, 9 months
4Brock2016-09-2810 years, 0 months
5Dawn2024-06-152 years, 3 months
6Gary2026-02-100 years, 7 months
=DATEDIF(B2, DATE(2026,9,28), "Y") & " years, " & DATEDIF(B2, DATE(2026,9,28), "YM") & " months"

The & symbol joins the numbers and the words together. You can also do this with CONCAT.

Ash has been a member for 89 months. That is 7 complete years (84 months) and 5 more months.

Note: Text in a formula must be inside double quotes: " ". Notice the spaces inside the quotes, like " years, ". Without them, the words would stick to the numbers.


Start Date After End Date

The start date must come first. If the start date is later than the end date, DATEDIF returns #NUM!.

This formula in G2 has the two dates in the wrong order:

ABG
1TrainerMember SinceWrong Order
2Ash2019-04-01#NUM!
=DATEDIF(DATE(2026,9,28), B2, "Y")

Swap the two dates to fix it: =DATEDIF(B2, DATE(2026,9,28), "Y")


See Also

To count the days between two dates, you can also subtract them. =DATE(2026,9,28)-B2 gives the same result as the "D" unit.

NETWORKDAYS counts only the working days between two dates, and TODAY returns the current date.


Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.