The Wayback Machine - https://web.archive.org/web/20240822182829/https://www.geeksforgeeks.org/datedif-function-in-excel/
Open In App

Excel DATEDIF Function

Last Updated : 20 Sep, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The DATEDIF is a date function that is generally used to find the number of total days, months, and years between two dates. It takes two dates as an argument with one keyword to specify which type of difference is required as an output. The output of the function will always be an integer form. 

DatedIF Function in Excel

The DATEDIF date function is used to find the difference between two dates(age in simple language). These differences can be in any form years, months, or days. It takes two dates as input with one keyword, where the one is the Start_date and the Second is the End_date, and the keyword is used to determine which type of difference is desired for the output.

Syntax

DATEDIF(start_date,End_date,unit)

Arguments

Datedif is the date function which is the in-built function in Excel.

Start_date: The beginning date from where you want to calculate the difference.

End_date: It is the last date of the period.

Unit: The type of information that you want to be returned.

Time Unit

Result

“Y” or “y”

The difference in complete years

“M” or “m”

The difference in complete months

“D” or “d”

The difference in complete days

“MD” or “md”

The difference in days, ignoring months and years

“YM” or “ym”

The difference in months, ignoring years

“YD” or “yd”

The difference in days, ignoring years.

The time unit to utilize while ascertaining the difference between two dates.

Excel DATEDIF Formula

To find the difference between the two dates in Excel, the important thing is to provide the start and end dates to the DATEDIF function. This can be done in multiple ways as follows:

Cell References

This is 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 takes dates as a string for example “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 calculateinto the number of months between the specified dates:

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

Serial numbers

Microsoft Excel stores each date as a serial number beginning with January 1, 1900, you use numbers corresponding to the dates. But 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")

How to Use DATEDIF Function in Excel

There are three formulas to calculate year, month, and days:

For the total number of years = datedif(a3,b3,”y”)

Example 1: The Total Number of Years Between the Two Dates

Step 1: Enter the Start Date and End Date.

Step 2: Now enter the formula in a cell where you want to calculate the age.

Formula to calculate age in years

This formula will give you the total number of years between the two dates.

Age in years

Example 2: The Total Number of Months Between the Two Dates

For a total number of months 

 =datedif(a3,b3, “m”)

Where the first argument is the field and the “m” represents the month.

Step 1: Enter the Start_date and End_date.

Step 2: Enter the formula in a cell where you want the number of months between two dates.

Formula to calculate age in months.

In the below image, you can see the total number of months between the two dates.

age in months.

 Example 3: Number of Days Between Two Dates

For the total number of days   =datedif(a3,b3, “d”) 

 Where the first argument is the field and the “d” represents the day.

Step 1: Enter the Start_date and End_date.

Step 2: Enter the formula in the cell where you want the total number of months.

formula to calculate age in days

Total number of days between the two dates (Start_date and End_date).

age in days.

Arguments 

1. The start date is typed in DDMMYYYY format. You can select the date format in the home tab from the number.

Format of Date

2. The last date or end date is typed in DDMMYYYY format.

3. The “y” for the years unit, “m” for the month unit, and “d” for the days unit.

4. The sixth type of unit (“y”, “m”, “d”, )  (“ym”,”md”, “yd”)  

  • “ym” means the number of months without years,  “md” means the number of days  without years and months,
  • “yd” means the number of days without years

Example 4: Find the Number of Months Excluding Days and Years

By this function, we can find our age (in years months, and days) from our date of birth to the current date. Suppose any person’s birth date is 26 January 1969 and the current date is 05 May 2020 (exact in years, months, and days ).

Step 1: Enter the DOB of the Person and the Current date(You can use Today() instead of the current date).

Step 2: Now Use the formula (=datedif(dob,current_date) in a cell where you want the age of the person. 

Formula to calculate age in years and month.

In the image given below, we can see the total number of months excluding years and days.

age in years and months.

Example 5: Total Number of Days Excluding Months and Years

Step 1: Enter the DOB and current date of the person.

Step 2: Enter the formula (=datedif(DOB, Current_date) in a cell, where you want the age in days excluding years and months.

Formula to calculate age in dd-mm--yy

You can see the output in the below image, the number of days excluding years and months.age in dd-mm-yy

Frequently Asked Questions

What is the DATEDIF function in Excel?

DATEDIF is the Built- in date function which is used to calculate the the difference between two given dates in days, months and years.

It takes two dates with one keyword as an argument. 

What are the advantages of using the DATEDIF function?

1. It is easy to use and understand.

2. This function is useful to see the difference between two dates in Years, Months, Days.

What are the Disadvantages of using the DATEDIF function?

  • Excel supports only six types of intervals in DATEDIF function.
  • It cannot give the output for so many units like the first day of the week.
  • May lead to confusion because of too many parameters in a single formula.
  • It might give wrong output if correct date format has not been used.



Similar Reads

How to Calculate Age Without DATEDIF Function
When it comes to calculating age in Excel, most users typically rely on the DATEDIF function. However, what happens if this function is unavailable or you prefer an alternative approach? In this article, we'll explore different ways of finding age in Excel, other than the usual way of finding age using the DATEDIF function. However there is no spec
4 min read
Editing Excel Macros in Excel
Excel Macro is a set of actions that can be recorded, saved, used multiple times. This feature saves us a lot of time when dealing with repetitive tasks and huge data sets. We can always make changes to an existing Macro in Excel. There are two ways to record and run macros: Excel Commands Excel Visual Basic for Applications(VBA).1. Copying a Macro
1 min read
Best Microsoft Excel High-Paying Jobs with Excel Skills in 2024
Master Essential Skills to Launch Your Career with Microsoft Excel, the world's leading spreadsheet software. Dominate data analysis, financial modelling, and project management tasks used by organizations of all sizes. Excel proficiency is a highly sought-after skill that can boost your resume and open doors to high-paying jobs. Excel High-Paying
14 min read
What Is the Difference Between VAR.S Function and VAR.P Function in Excel?
Functions in Excel are the pre-defined formulae used to obtain a certain value and to perform calculations using the specific value in a certain order. The basic functions are SUM, AVG, MAX, MIN, etc used for the range of cells. In order to obtain the correct results from the function, the correct syntax of the functions is required. In this articl
6 min read
Use Custom Data Validation Function To Limit Number of Digits In Excel
There might arise a situation while working on Excel where you want the users to type in 10-digits(say) numbers only in a cell. In these types of scenarios, we can make use of the Custom Data validation Function to limit the number of digits in Excel. In this article, we will discuss the same. Sample Data: Customer Sales Table Approach: First, we c
1 min read
Gestep Function In Excel
GESTEP is a function in Microsoft Excel that is used to check whether the given number is greater than the given threshold value(given step value). It returns 1 i.e. True , if the number is greater than the step value and, It returns 0 i.e. False , if the number is lesser than the step value. Formula of GESTEP function: =GESTEP(number, [step]) Here
2 min read
IFERROR Function in Excel With Examples
Excel is a useful tool for data handling, and it is widely used worldwide. The built-in functions make this application more user-friendly. Such a function is the IFERROR function. This function helps to trap and handles the errors while using a formula(such as dividing something by '0'). This function is very useful to an Excel user. This function
3 min read
MATCH Function in Excel With Examples
Excel contains many useful functions and such a function is the 'MATCH()' function. It is basically used to get the relative position of a specific item from a range of cells(i.e. from a row or a column or from a table). This function also supports exact and approximate match like VLOOKUP() function. Generally, MATCH() function is used with the IND
3 min read
OFFSET Function in Excel With Examples
Excel contains many useful formulas and functions that make it more and more useful and at the same time user-friendly. Such a function is the OFFSET() function. In many cases, this function is also used inside another function. This function basically returns a reference of a single cell or a range of cells depending on the input. With the help of
4 min read
Using CHOOSE Function along with VLOOKUP in Excel
In Excel, managing space is a very important point to consider. Now, let's suppose you are in a situation where you want to compare multiple columns in the Excel dataset, and you want to derive results, This is not possible using the VLOOKUP function alone. So, to make a function capable of doing something like this, we will introduce a special fun
2 min read
InputBox Function in Excel VBA
Input Box is one of the most frequently used functions in VBA Macro. The dialogue box that appears asks for input from the user and returns a constant/code/number/text. For example, if you want to create a log-in form in VBA, you will require an input box function. Let's learn how to create an input box in VBA. InputBox FunctionInput Box is a dialo
11 min read
How to Use the Excel STDEV.P Function?
The STDEV.P Function is ordered under Excel Statistical capabilities. STDEV.P will work out the standard deviation that depends on a whole populace given as contentions. It will disregard legitimate qualities and text. As a monetary expert, the STDEV.P capability can be helpful in, for instance, working out deviations in income. Portfolio administr
3 min read
Function and Sub in Excel VBA
In Visual Basic, the functions and sub-procedures play similar roles but have different or unique characteristics. However, both perform a programmed task. They utilize a set or group of commands to deliver the required results. The key difference between the sub and the functions is that a sub-procedure generally does not return a result whereas f
4 min read
Normdist() Function in Excel
The NORMDIST Function is one of Excel's Statistical functions. For a given mean and standard deviation, it will yield the normal distribution. That is, for a given set of parameters, it will compute the normal probability density function or the cumulative normal distribution function. In this article, we will discuss NORMDIST Function with a few e
3 min read
Excel MID Function
If you use programming languages, like Python, you must have used a function called string slicing, which extracts a part of the string and can directly print it, or store a result. The same functionality can be achieved in Excel when we use Excel's MID function. The MID function can return a part of the string provided to it. Let us see the workin
7 min read
Excel CHOOSE Function with Array
We often use the CHOOSE function in Excel to pick something from a list. In this article, we'll see how to use CHOOSE with a bunch of things (we call it an array) to do various stuff in Excel. This array can be either many cells we put into the function or many things we get from the function. What is CHOOSE Function with Array in ExcelThe Excel CH
5 min read
How to use MINIFS function in Microsoft Excel
The MINIFS function in Excel is a powerful tool for filtering and analyzing data. It allows you to find the smallest numeric value in a range of cells that meet one or more specified requirements. This can be useful for a variety of tasks, such as finding the lowest price for a product in a specific category, finding the shortest delivery time for
11 min read
How to use the IFS function in Excel
The IFS function in Excel acts as a keen partner, making choices for your information. It's perfect when you have different rules and wish to grant prizes based on those rules. Rather than getting misplaced in complicated enlightening, IFS assists your information in getting to where it ought to go. It's interesting that once you have several condi
7 min read
Excel HLOOKUP Function with Formula Examples
Excel has several functions to search data from a table. HLOOKUP() function is one of them. The 'H' in the HLOOKUP() function stands for 'horizontal'. This function generally helps to find a value from a row of an array or table. For this function to work the lookup value must be in the first row of the table or array. HLOOKUP() moves downward and
8 min read
How to Debug a User Defined Function in Excel VBA
In this article, we will understand debugging user-defined functions (UDFs) in Excel VBA. Debugging is a fancy term, but think of it as detective work for your code. When your UDF is not working as expected, debugging can help you to identify and fix the issues. What is Debugging in Excel VBA Debugging is a way of identifying and fixing errors in a
5 min read
VBA Find Function in Excel
In an Excel sheet subset of cells represents the VBA Range which can be single cells or multiple cells. The find function will help to modify our search within its Range object. A specific value in the given range of cells is to search with the help of the Find function. Excel VBA provides different parameters in the Find function so that we can se
5 min read
How to Create an Excel Step Chart Formula Using the Small Function?
A step Chart is a kind of line chart which uses horizontal and vertical lines to connect two different data points and forms a step-like structure. Unlike a line chart, it does not use the shortest distance to connect two different data points. A step chart is used to display data that varies unevenly over time. A step chart is useful in representi
3 min read
How to Create a User Defined Function in Excel VBA
A function is a collection of code.  As a developer, we very often need a custom function (User-defined function) in our projects. These functions can be used as normal functions in Excel. These are helpful when the existing functions are not enough. In such cases, the user can create his own custom user-defined function to fulfil the need.  What a
6 min read
How to use CHOOSE Function in Excel
The CHOOSE function is technically part of Excel’s lookup function and can be incredibly useful. The CHOOSE function returns a value from a list using an index. One of those Excel features, CHOOSE, may not seem helpful alone, but when paired with other functions, it offers a ton of fantastic advantages. In most basic form, the CHOOSE function allow
7 min read
How to Use the UNIQUE Function in Excel
No need to Manually Remove Duplicates in Excel. Make it easy and Quick Using UNIQUE Function to Remove Duplicates in Excel. In this article, we are going to learn How to Remove Duplicates in Excel Using UNIQUE Function. Table of Content What is the Unique Function in ExcelHow to Use the UNIQUE Function to Remove DuplicatesHow does a Unique Function
6 min read
Excel SORT Function
Explore the power of your Excel data with our easy-to-follow guide on Excel Sort Function. Whether you’re a beginner or an experienced professional, learning Excel’s sorting and filtering tools can enhance your workflow and provide valuable insights. This article explores each step, ensuring you can organize your data efficiently and effectively. W
6 min read
Excel IF function With Examples
Are you ready to unlock the full potential of Excel and take your data analysis skills to the next level? The Excel IF function is a powerful tool that allows you to make logical comparisons between a value and what you expect. Whether you're dealing with a single condition or multiple conditions, the IF function can simplify complex decision-makin
8 min read
XLOOKUP Function in Excel With Examples
Are you tired of struggling with Excel’s VLOOKUP formula limitations? Meet XLOOKUP, the game-changing function designed to simplify your data management tasks. With the XLOOKUP function, Excel users can effortlessly find values in a table or range by row, eliminating the need for complex workarounds. This powerful tool not only streamlines your wor
8 min read
INDEX and MATCH Function in Excel
If you're looking to master Excel and elevate your data analysis skills then you have to explore excel formulas, understanding the INDEX and MATCH functions in Excel is essential. These powerful Excel formulas go beyond basic lookup functions like VLOOKUP, offering unmatched flexibility and efficiency. So, what does INDEX MATCH do in Excel? Simply
13 min read
SUMIF Function in Excel with Examples
Quick Steps to Use the SUMIF Function in ExcelOpen Excel and select the cell where you want the sum.Enter Formula: Type =SUMIF(.Specify Range: Select the range to evaluate (e.g., A1:A10).Enter Criteria: Type the criteria in quotes (e.g., "Apples").Specify Sum Range: Select the range to sum (e.g., B1:B10).Complete Formula: Type ) and press Enter.Eve
9 min read
three90RightbarBannerImg