Calculate Years and Months between Two Dates in Excel

All of our everyday tasks are dependent on time. We must keep track of time because time is a transient circumstance. Years, months, days, etc. are used to measure the time. In Microsoft Excel, we can calculate the years, months, days, hours, etc.; actually the measurements of time between two dates. In this article, we will demonstrate different ways to calculate years and months between two dates in Excel.


Suppose, you are in charge of a number of tasks, you may want to remember how several months and years have transpired between two dates. Or you need to calculate someone’s age between two dates.

To calculate years and months between two dates we are going to use this dataset. The dataset contains some start dates and end dates and the number of years and months passed between the two dates. Now, Let’s go through the methods and learn to calculate years and months using those methods.

6 Different Approaches to Calculate Years and Months between Two Dates


1. Using Excel DATEDIF Function to Calculate Years and Months Between Two Dates

To calculate years and months between two dates, the DATEDIF function is the best option in Excel. Let’s have a basic understanding of the DATEDIF function first.

Syntax:

The syntax for the DATEDIF function is:

DATEDIF(start_date,end_date,unit)

Arguments:

start_date: The first date is often known as the commencement date.

end_date: A date that signifies the end of a period of time.

unit: The kind of information you’d like to get (“y”, “m”, “ym”, etc.)


1.1. Calculating Age in Years

Assume that you want to calculate the age of some people for a particular time. For this, we need to know the birth date which is the start date in our dataset and also we need to know the exact day which we consider as the end date in our dataset. Now let’s calculate how old they were on that particular date. To calculate the year, we are using the DATEDIF function. Let’s follow the steps down.

STEPS:

  • First, select the cell where you want the calculated year. So we select cell D5.
  • Then, type the formula on that cell.
=DATEDIF(B5,C5,"y")

Here, cell B5 indicates the start date and cell C5 indicates the end date. We use y as the unit because we want the difference between two dates in years.

  • After that, press Enter. The formula will be shown in the formula bar.

6 Different Approaches to Calculate Years and Months between Two Dates

  • To copy the formula over the dataset, drag the Fill Handle down.

6 Different Approaches to Calculate Years and Months between Two Dates

  • And, that’s it! The years are calculated in the resulting cell.


1.2. Calculating Age in Months

Likewise the previous section of 1.1, now we want to calculate the months of those persons. Again, we are using the DATEDIF function to calculate the months. For this, we need to go after the procedures.

STEPS:

  • Choose the cell where you wish the calculated month to appear.
  • Select cell D5 and type the formula below.
=DATEDIF(B5,C5,"m")

Here, cell B5 represents the start date, whereas cell C5 represents the end date. We insert m as the unit because we’re looking for the difference in months between the two dates.

  • After that, hit the Enter key. In the formula bar, the formula will appear.

6 Different Approaches to Calculate Years and Months between Two Dates

  • Next, drag the Fill Handle down to duplicate the formula over the dataset.

6 Different Approaches to Calculate Years and Months between Two Dates

  • That’s all there is to it! In the resultant cell, the months are calculated.


1.3. Marging Excel Formula to Calculate Age in Years and Months

Here, we want to calculate the years and months using the DATEDIF function.

STEPS:

  • Enter the formula into cell D5.
=DATEDIF(B5,C5,"y")&" years" &", "&DATEDIF(B5,C5,"m")&" months"

Here, cell B5 signifies the start date, and cell C5 signifies the end date.

  • Then press the Enter key. The formula will be displayed in the formula bar.

  • Drag the Fill Handle down to copy the formula over the dataset.

6 Different Approaches to Calculate Years and Months between Two Dates

  • That’s it! In the resulting cell, the years and months are computed.

Read More: How to Calculate Tenure in Years and Months in Excel


2. Applying Excel LET Function Calculate Years and Months

By using the LET function, we can calculate the years and months between two dates in Excel. Let’s start with a fundamental overview of the LET function.

Syntax:

The syntax for the LET function is:

LET (name1, name_value1, [name2], [name_value2], …, calculation)

Arguments:

name1: This is the first name to be assigned. It needs to start with a letter.

name_value1: Name1’s assigned value or calculation.

[name2] / [name_value2]: The second name, as well as its worth.

calculation: A calculation that employs names and values that have been assigned.

Now, Let’s have a look at the steps below.

STEPS:

  • In the beginning, select the cell where you want the calculated years and months to appear. So we picked cell D5.
  • Next, insert the formula in that cell.
=LET(start,B5,end,C5, DATEDIF(start,end,"y")&" years, "& DATEDIF(start,end,"m")&" months")

Calculate Years and Months Using Excel LET Function

Here, cell B5 denotes the start date, while cell C5 denotes the end date.

  • Then, press the Enter key. And the formula will appear in the formula bar.

Calculate Years and Months Using Excel LET Function

  • Now, drag the Fill Handle down to copy the formula over the range.

Calculate Years and Months Using Excel LET Function

  • And finally, the years and the months are calculated in the resulting cells.

Calculate Years and Months Using Excel LET Function

Read More: How to Calculate Years Between Two Dates in Excel


3. Computing Years & Months between Two Dates with YEARFRAC Function

We can calculate years and months with the YEARFRAC function in Excel. First, let’s review the YEARFRAC function in its most basic form.

Syntax:

The syntax for the YEARFRAC function is:

YEARFRAC(start_date, end_date, [basis])

Arguments:

start_date: The start date is represented by this date.

end_date: The termination date is represented by this date.

[basis]: The day count basis to be used.


3.1. Calculating Years between Two Dates

To calculate years using the YEARFRAC function we need to follow the steps below.

STEPS:

  • To begin, choose the cell in which you want the calculated years to appear. So, we choose cell D5.
  • Then, write down the formula there.
=YEARFRAC(B5, C5)

Here, cell B5 symbolizes the starting date, and cell C5 symbolizes the ending date.

  • After that, press Enter. The formula will be shown in the formula bar.

  • Further, drag the Fill Handle down to repeat the formula over the set of data.

  • You will see the result by following the above steps.


3.2. Calculating Months between Two Dates

To use the YEARFRAC function to calculate months, follow the instructions below.

STEPS:

  • Select cell D5 and insert the formula given below.
=YEARFRAC(B5,C5)*12

Here, cell B5 indicates the start date and cell C5 indicates the end date.

  • Then, hit Enter. And you will be able to see the formula in the formula bar.

  • After that, copy the formula over the range D5:D8 by dragging the Fill Handle down.

Calculate Months between two Dates

  • Finally, the months are calculated between the two dates.

Read More: How to Calculate Years from Today in Excel


4. Calculating Duration between Two Dates Without Zero Value

Suppose, we need to find the difference between two dates without displaying the zero values. We can do this by combining the IF and DATEDIF functions in Excel. Let’s take a look at the steps below.

STEPS:

  • First, select cell D5.
  • Next, type the formula there.
=IF(DATEDIF(B5,C5,"y"), DATEDIF(B5,C5,"y")&" years","")& IF(DATEDIF(B5,C5,"m"),", "&DATEDIF(B5,C5,"m")&" months","")

Calculate the Duration between Two Dates Without Zero Value

  • After that, drag the Fill Handle down.

Calculate the Duration between Two Dates Without Zero Value

  • This will calculate the duration between two dates without having zero values.

Calculate the Duration between Two Dates Without Zero Value

Read More: How to Count Months from Date to Today by Using Excel Formula


5. Combining YEAR and MONTH Functions to Count Months in Excel

To calculate months between two dates, we can use the YEAR and MONTH functions together in Excel. Let’s take a look at the procedures below.

STEPS:

  • Move to cell D5 and write the formula in that cell.
=(YEAR(C5)-YEAR(B5))*12+MONTH(C5)-MONTH(B5)

Combine YEAR and MONTH Functions to Count Months in Excel

  • After that, hit Enter.

Calculate the Duration between Two Dates Without Zero Value

  • Next, simply drag the Fill Handle down.

Combine YEAR and MONTH Functions to Count Months in Excelates Without Zero Value

  • And, there you go!

Read More: How to Find Number of Weeks Between Two Dates in Excel


6. Applying VBA to Calculate Years and Months Between Two Dates

With Excel VBA, we may do a wide range of activities. We can calculate years and months between two dates using the VBA code. So let’s see the steps down to use the VBA to calculate years and months between two dates.

STEPS:

  • First, go to the Developer tab on the ribbon.
  • Click on Visual Basic or press Alt + F11 to open the Visual Basic Editor.

Excel VBA to Calculate Years and Months Between Two Dates

  • Another way to open the Visual Basic Editor is to simply right-click on the sheet and select View Code.

  • This will open the Visual Basic Editor where you can write the code.
  • Now, write down the VBA code below.
Sub Years_and_Months_Between_Two_Dates()
    Dim StartDate As Date, EndDate As Date
    Dim year As Integer
    Dim month As Integer
    StartDate = "1-Jan-2020"
    EndDate = "15-Mar-2022"
    year = DateDiff("yyyy", StartDate, EndDate)
    month = DateDiff("m", StartDate, EndDate)
    MsgBox "Number of years: " & year, vbInformation, "Years Between Two Dates"
    MsgBox "Number of months: " & month, vbInformation, "Months Between Two Dates"
End Sub
  • Next, run the code by pressing the F5 key or clicking the Run Sub button.

  • And, this will first show the number of years in the MsgBox.

  • Then, click on the OK button to show the number of months between the given two dates.

Read More: Calculate Number of Days between Two Dates with VBA in Excel


Download Practice Workbook

You can download the workbook and practice with it.


Conclusion

The above methods will assist you in calculating years and months between two dates in Excel. Hope this will help you! If you have any questions, suggestions, or feedback please let us know in the comment section.


Related Articles


<< Go Back to Days Between Dates | Calculate Dates | Date-Time in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Sabrina Ayon
Sabrina Ayon

Sabrina Ayon, a Computer Science and Engineering graduate from United International University, has been an integral part of the ExcelDemy project for two years. She authored 150+ articles, excelling in instructing through visually engaging Excel tutorials. With a passion for teaching, Sabrina conducted sessions on Excel VBA, sharing her knowledge and insights with others. Currently holding the position of Project Manager for the ExcelDemy Visual Development Project, she oversees various aspects of the project, ensuring its smooth operation... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo