How To Calculate Months Between Two Dates In Excel 2017

Excel 2017 Months Between Dates Calculator

Calculate the exact number of months between two dates with precision – just like Excel 2017’s DATEDIF function

Total Months Between Dates
Complete Months (DATEDIF “m”)
Remaining Days (DATEDIF “md”)
Excel Formula Equivalent

Comprehensive Guide: How to Calculate Months Between Two Dates in Excel 2017

Calculating the number of months between two dates is a common requirement in financial analysis, project management, and data reporting. Excel 2017 provides several methods to accomplish this, each with different behaviors regarding partial months and day counts. This guide explains all available techniques with practical examples.

The DATEDIF Function: Excel’s Hidden Gem

The DATEDIF function (Date Difference) is Excel’s most powerful tool for date calculations, though it’s not officially documented in Excel 2017’s help files. This function can calculate differences in years, months, or days between two dates with various unit options.

Why DATEDIF Isn’t Documented

The DATEDIF function originates from Lotus 1-2-3 and was included in Excel for compatibility reasons. Microsoft never officially documented it, but it remains fully functional in Excel 2017 and later versions.

DATEDIF Syntax and Unit Options

The basic syntax is:

=DATEDIF(start_date, end_date, unit)

Where unit can be one of these values:

  • “y” – Complete years between dates
  • “m” – Complete months between dates
  • “d” – Days between dates
  • “ym” – Months between dates (ignoring years)
  • “yd” – Days between dates (ignoring years)
  • “md” – Days between dates (ignoring months and years)

Practical Examples

Let’s examine how to calculate months between January 15, 2020 and March 10, 2021:

Formula Result Explanation
=DATEDIF(“1/15/2020”, “3/10/2021”, “m”) 13 Complete months between dates (1 year and 1 month = 13 months)
=DATEDIF(“1/15/2020”, “3/10/2021”, “ym”) 1 Months difference ignoring years (March – January = 1 month, ignoring the 2021-2020 difference)
=DATEDIF(“1/15/2020”, “3/10/2021”, “md”) 23 Days difference ignoring months and years (March 10 – January 15 = 23 days)

Combining DATEDIF for Complete Solutions

For most real-world scenarios, you’ll need to combine multiple DATEDIF calculations:

  1. Total months including partial:
    =DATEDIF(start, end, "y")*12 + DATEDIF(start, end, "ym")
    This gives the total months counting partial months as full months.
  2. Exact months with decimal:
    =DATEDIF(start, end, "m") + (DATEDIF(start, end, "md")/30)
    This approximates partial months as decimal values (assuming 30-day months).
  3. Complete months only:
    =DATEDIF(start, end, "m")
    This counts only complete calendar months between dates.

Alternative Methods in Excel 2017

While DATEDIF is the most precise method, Excel 2017 offers alternative approaches:

1. Using YEARFRAC and ROUND

=ROUND(YEARFRAC(start_date, end_date, 1)*12, 2)

This calculates fractional years and converts to months. The third parameter (1) specifies the day count basis (actual/actual).

2. Using EDATE in a Loop

For VBA solutions, you can use EDATE in a loop to count months:

Dim months As Integer
months = 0
Do While startDate <= endDate
    months = months + 1
    startDate = Application.WorksheetFunction.EDATE(startDate, 1)
Loop

3. Simple Subtraction with Division

=ROUND((end_date - start_date)/30, 2)

This rough estimate divides the day difference by 30. Not recommended for precise calculations.

Handling Edge Cases

Date calculations often involve special cases that require careful handling:

Scenario Solution Example
End date earlier than start date Use ABS or IF to handle negative results =IF(DATEDIF(A1,B1,"m")<0, 0, DATEDIF(A1,B1,"m"))
Leap years (February 29) DATEDIF automatically handles leap years correctly =DATEDIF("2/29/2020", "2/28/2021", "m") returns 12
Different day counts in months Use "md" unit for remaining days after complete months =DATEDIF("1/31/2020", "2/28/2020", "md") returns 28
Blank or invalid dates Use IFERROR to handle errors gracefully =IFERROR(DATEDIF(A1,B1,"m"), "Invalid date")

Performance Considerations

For large datasets in Excel 2017:

  • DATEDIF is fastest - Native function optimized for performance
  • Avoid volatile functions - INDIRECT or TODAY can slow recalculations
  • Use helper columns - Break complex calculations into steps
  • Limit array formulas - They consume more resources in Excel 2017
  • Consider Power Query - For transforming date columns in large datasets

Real-World Applications

Months-between-dates calculations appear in many business scenarios:

  1. Financial Analysis:
    • Calculating loan terms in months
    • Determining investment holding periods
    • Amortization schedule creation
  2. Human Resources:
    • Employee tenure calculations
    • Probation period tracking
    • Vacation accrual based on service months
  3. Project Management:
    • Project duration in months
    • Milestone tracking
    • Resource allocation planning
  4. Contract Management:
    • Service period calculations
    • Warranty duration tracking
    • Renewal notice timing

Common Mistakes to Avoid

Even experienced Excel users make these errors with date calculations:

  1. Assuming all months have 30 days - This leads to inaccurate results, especially for February and 31-day months
  2. Ignoring the order of dates - Always ensure end_date ≥ start_date or handle negative results
  3. Using TEXT functions for calculations - Functions like MONTH() extract components but don't calculate differences
  4. Forgetting about time components - Dates with times may give unexpected results; use INT() to remove times
  5. Hardcoding date formats - Use cell references instead of text dates to avoid locale issues
  6. Not accounting for leap years - DATEDIF handles this automatically, but custom formulas might not

Advanced Techniques

For complex scenarios, consider these advanced approaches:

1. Creating a Months Between UDF

Write a custom VBA function for specialized calculations:

Function MonthsBetween(startDate As Date, endDate As Date, Optional includePartial As Boolean = True) As Variant
    Dim fullMonths As Integer
    Dim daysRemaining As Integer

    If endDate < startDate Then
        MonthsBetween = CVErr(xlErrValue)
        Exit Function
    End If

    fullMonths = DateDiff("m", startDate, endDate)
    daysRemaining = DateDiff("d", Application.WorksheetFunction.EDATE(startDate, fullMonths), endDate)

    If includePartial Then
        MonthsBetween = fullMonths + (daysRemaining / 30)
    Else
        MonthsBetween = fullMonths
    End If
End Function

2. Using Power Query for Large Datasets

For datasets with thousands of rows:

  1. Load data into Power Query
  2. Add custom column with Duration.Days([end_date] - [start_date])
  3. Divide by 30 and round to get approximate months
  4. Or use Date.Month to extract month components

3. Conditional Formatting Based on Month Differences

Highlight cells where the months between dates exceeds a threshold:

  1. Select your date range
  2. Go to Conditional Formatting > New Rule
  3. Use formula: =DATEDIF(A1,B1,"m")>12
  4. Set your desired format

Frequently Asked Questions

  1. Why does DATEDIF give different results than simple subtraction?

    DATEDIF accounts for actual calendar months, while simple subtraction divides by 30. For example, Jan 31 to Feb 28 is 0 months in DATEDIF ("m") but would be ~28/30 = 0.93 in simple division.

  2. How do I calculate months between dates excluding weekends?

    Use NETWORKDAYS to count business days, then divide by 21 (average business days per month):

    =NETWORKDAYS(start, end)/21

  3. Can I calculate months between dates in Excel Online?

    Yes, DATEDIF works identically in Excel Online and Excel 2017. The function is available in all modern Excel versions.

  4. Why does =DATEDIF("1/31/2020","2/28/2020","m") return 0?

    Because February 28 is before the next complete month after January 31 (which would be February 29 in 2020). DATEDIF counts complete calendar months.

  5. How can I display the result as "X years and Y months"?

    Combine multiple DATEDIF calls with text:

    =DATEDIF(A1,B1,"y") & " years and " & DATEDIF(A1,B1,"ym") & " months"

Pro Tip: Date Serial Numbers

Excel stores dates as serial numbers (days since Jan 1, 1900). You can use this for calculations:

=ROUND((B1-A1)/30.44, 2)
The 30.44 divisor accounts for average month length (365.25 days/year ÷ 12 months).

Leave a Reply

Your email address will not be published. Required fields are marked *