How to Get Months Between Dates in Excel
Learn multiple Excel methods to get months between dates with step-by-step examples, troubleshooting tips, and real-world applications.
How to Get Months Between Dates in Excel
Why This Task Matters in Excel
Tracking the number of months that pass between two dates is a core requirement across almost every industry that relies on time-based data analysis. Finance teams need to calculate the number of months to determine loan amortization schedules, interest accrual, and debt‐restructuring timelines. Human Resources departments monitor employee tenure and benefits eligibility based on months of service. Supply-chain managers count the months between production runs or contract renewals, while marketing analysts caveate spend effectiveness by knowing exactly how many months a campaign has been running.
Excel is uniquely positioned to handle date arithmetic, yet many users struggle because dates, unlike plain numbers, follow a built-in serial system, and month lengths vary. A simple subtraction of one date from another gives days, not months. Even seasoned analysts occasionally convert months manually or with cumbersome workarounds, introducing errors that cascade through dashboards and financial statements.
Mastering reliable “months between” logic unlocks more advanced workflows such as dynamic cash-flow models, capacity planning, lease accounting under IFRS 16 or ASC 842, and customer churn forecasting. Knowing the right formula eliminates guesswork, keeps calculations auditable, and prevents embarrassing reporting discrepancies. Just as important, this skill dovetails with other time functions—quarter calculations, year fractions, working-day offsets—so your overall date-handling proficiency improves in tandem.
Best Excel Approach
When you only need whole months (ignoring leftover days), the most straightforward method is DATEDIF with the \"m\" unit. Despite being undocumented in Excel’s formula list, it has existed since Lotus 1-2-3 compatibility days and behaves reliably across modern versions.
Syntax and logic:
=DATEDIF(start_date, end_date, "m")
start_date– the earlier dateend_date– the later date"m"– unit code requesting the count of complete calendar months between the dates
Why this is usually best:
- Simplicity: one concise formula returns whole months without helper columns.
- Accuracy: it handles different month lengths automatically.
- Flexibility: change the unit to
"ym"to get remaining months after subtracting full years, or"md"to get leftover days.
Use this method when you only need full-month counts—loan duration, subscription periods, tenure bands, etc.—and the start date is always earlier than the end date. If you need fractional months or must handle reversed dates without errors, alternatives below may suit better.
Alternative one-cell formula (no DATEDIF)
If your organization blocks DATEDIF or you prefer documented functions, the following arithmetic delivers identical results:
=(YEAR(end_date)-YEAR(start_date))*12 + MONTH(end_date)-MONTH(start_date) - (DAY(end_date)<DAY(start_date))
It converts year differences to months, adds leftover months, and subtracts one when the end-day is earlier in the month than the start-day—ensuring only complete months are counted.
Parameters and Inputs
- Start Date (
start_date): Any valid Excel date, typically a cell like [A2]. Ensure the cell is either date-formatted or holds the correct serial number behind the scenes. - End Date (
end_date): Another valid date, often in [B2]. It should represent a point in time the same or later than the start date if you expect a non-negative result. - Unit (for DATEDIF): A text string inside quotes. Common units relevant here:
‒"m"– complete months between dates
‒"ym"– months remaining after full years are excluded
‒"md"– leftover days ignoring months and years
Preparation guidelines:
- Confirm both inputs are actual dates, not text that looks like dates. Test with the
ISNUMBERfunction; it should return TRUE. - Standardize locale: if colleagues run regional settings with day-month vs month-day, enter dates with
DATE(year,month,day)to avoid misinterpretation. - Decide on inclusive vs exclusive logic—Excel counts full months; partial months are ignored unless you switch to a fractional method.
- Guard against reversed inputs by wrapping with
ABSor nesting inIFERRORif the order is unpredictable. - Large data imports often include blanks or “N/A” placeholders; employ
IF(ISBLANK())wrappers or data validation to trap them.
Step-by-Step Examples
Example 1: Basic Scenario
Imagine a small HR sheet with employee hire dates and today’s date:
| Employee | Hire Date | Today |
|---|---|---|
| Ana | 15-Jan-2020 | 26-Jul-2023 |
| Bruno | 01-Mar-2021 | 26-Jul-2023 |
| Carla | 30-Apr-2023 | 26-Jul-2023 |
Steps:
- Enter the hire dates in cells [B2:B4] with proper date formatting.
- In [C2], type
=TODAY()and copy downward. - In [D2], calculate months of service:
=DATEDIF(B2, C2, "m")
- Copy [D2] down to [D4]. Results: 42, 28, and 2 respectively.
Why it works: DATEDIF counts full calendar months, so Ana’s 15-Jan-2020 to 26-Jul-2023 covers 42 full months (3 years + 6 months). Carla’s partial April-to-July period yields 2 because the 30-day mark in July has not yet been reached.
Common variations:
- Replace
TODAY()with a fixed date for retrospective analysis. - Switch to
"ym"in a helper column to list the leftover months after full years, letting you create a “3 years 6 months” concatenation:"42 months"or"3y 6m"display.
Troubleshooting: If you see#NUM!, one of your start dates might be later than the end date—wrap the formula inIF(B2>C2,"-",DATEDIF(B2,C2,"m"))or simply swap the arguments.
Example 2: Real-World Application
Scenario: A commercial bank reviews auto-loan portfolios, each with a contract start and maturity date. Management wants to know how many repayment months remain so they can forecast monthly inflows.
Data snapshot:
| Contract | Start Date | Maturity Date | Balance |
|---|---|---|---|
| XA102 | 10-Feb-2020 | 10-Aug-2025 | $18 000 |
| XA103 | 02-Nov-2019 | 02-Nov-2024 | $ 7 400 |
| XA104 | 27-Sep-2022 | 27-Dec-2026 | $16 250 |
Step-by-step:
- Place the loan table in [A2:D4].
- In [E1], label “Months Remaining”.
- In [E2], craft the formula using today’s date:
=DATEDIF(TODAY(), C2, "m")
- Drag to [E4]. You get 25, 15, and 41 respectively.
- Create a projected cash-flow for the next month only when balance exists:
=IF(E2>0, Balance_per_month, 0)
To calculate Balance_per_month, divide [D2] by [E2].
Integration benefits: The months-remaining figure feeds into a SUMPRODUCT model that projects principal collections by month, populating dashboards instantly whenever the current date changes.
Performance tips: On portfolios with 20 000 loans, volatile functions like TODAY() recalculate each worksheet change. Instead, store today’s date once in a settings cell and reference that cell throughout to reduce recalc time.
Example 3: Advanced Technique
Edge case: You need fractional months for actuarial reserve calculations, where each premium accrues daily. Whole months aren’t granular enough.
Approach: YEARFRAC multiplied by 12.
- Policy start in [B2] = 18-Mar-2021, valuation date in [C2] = 07-Sep-2023.
- In [D2], calculate fractional months:
=YEARFRAC(B2, C2, 1)*12
The third argument 1 selects the “actual/actual” day count convention. Result: 29.6452 months.
Professional considerations:
- Round to 2 decimal places with
ROUND, or to one decimal for management summaries. - Use array techniques on dynamic arrays for thousands of policies:
=ROUND(YEARFRAC([B2:B10000], ValuationDate, 1)*12, 2)
Memory optimization: YEARFRAC is heavier than DATEDIF; turn manual calculation on during formula entry if the sheet lags.
Error handling: YEARFRAC returns #VALUE! if either date is text—ensure data cleansing first.
Tips and Best Practices
- Anchor Today’s Date: Store today’s date in a dedicated settings cell (e.g., [F1]) rather than calling
TODAY()in thousands of rows; link your formulas to that cell. - Convert Text to Dates Quickly: Use
DATEVALUE()or Flash Fill to transform imports so DATEDIF won’t throw errors. - Document DATEDIF: Because it’s hidden from the Insert Function dialog, add a cell comment or note for colleagues so they don’t delete or “fix” it.
- Check Negative Results Early: Wrap formulas with
MAX(0, …)orIFERRORif there’s any chance the end date precedes the start date after data refreshes. - Create Dynamic “Years & Months” Labels: Combine
INT(months/12)andMOD(months,12)to produce human-friendly tenure strings. - Leverage Conditional Formatting: Highlight contracts with months remaining below 6 to alert renewal teams.
Common Mistakes to Avoid
- Swapping Start and End Dates: A reversed order in DATEDIF often returns
#NUM!. Prevent this by nesting inIF(start>end, "Error", …)or sorting your data first. - Relying on Text that Looks Like Dates: CSV imports treat dates as text; formulas then fail silently or produce nonsensical outputs. Always test with
ISTEXT()orISNUMBER(). - Ignoring Leap Years and Month Lengths: Manual arithmetic like
(end-start)/30assumes every month has 30 days—leading to sizeable cumulative errors over long time spans. - Using Integer Division on YEARFRAC:
INT(YEARFRAC()*12)truncates, but still includes partial months when the fraction is almost but not quite the next integer; confirm business rules before truncating. - Excessive Volatile Functions: Multiple
TODAY()orNOW()calls slow massive sheets. Centralize or use manual update toggles.
Alternative Methods
| Method | Whole Months | Fractional Months | Requires Add-in | Pros | Cons |
|---|---|---|---|---|---|
| DATEDIF | Yes | No | No | Simple, accurate, handles month length variations | Undocumented; lacks fractional option |
| YEAR/MONTH Arithmetic | Yes | With extra math | No | Fully documented functions, avoids DATEDIF | Slightly longer formula, extra day comparison needed |
| YEARFRAC × 12 | Yes (with ROUND or INT) | Yes | No | Supports actuarial bases, flexible day-count conventions | Heavier calculation load |
| Power Query | Yes | Yes | No | No-formula approach, great for large ETL tasks | Static snapshot unless you refresh |
| VBA UDF | Customizable | Customizable | Yes | Complete control over inclusive/exclusive logic | Requires macro‐enabled file, potential security prompts |
When precision or fractional months are mandatory, YEARFRAC outperforms. For ETL pipelines where you wish to load clean month counts into a data model, Power Query can add a custom column using M code Duration.Days([End]-[Start]) / 30.436875, then round. Use VBA only when corporate policy allows macros and you need bespoke logic like “count every 15th of the month as a billing cut-off”.
FAQ
When should I use this approach?
Use DATEDIF (or the arithmetic equivalent) whenever you need whole-month counts for schedules, aging buckets, or tenure labels. Switch to YEARFRAC × 12 when regulations specify proportional monthly accruals.
Can this work across multiple sheets?
Absolutely. Reference external sheets like:
=DATEDIF('Employee Data'!B2, 'Settings'!$F$1, "m")
Just keep sheet names in single quotes if they contain spaces.
What are the limitations?
- DATEDIF fails if the start date exceeds the end date.
- It cannot return negative results for reversed dates.
- No built-in option for fractional months.
Workarounds include wrapping the input order inABSor changing to YEARFRAC.
How do I handle errors?
Wrap formulas in IFERROR(value, "") to blank out issues, or design validation rules that highlight rows where start_date is after end_date. For data imports, coerce text dates with DATEVALUE() before applying month calculations.
Does this work in older Excel versions?
DATEDIF has existed since Excel 95. YEARFRAC arrived in the same era, so anything from Excel 2003 onward supports the examples shown. Dynamic arrays require Microsoft 365; if you’re on Excel 2010, array results need Ctrl + Shift + Enter.
What about performance with large datasets?
- Centralize volatile dates.
- Replace resource-intensive formulas with values after reconciliation (Copy → Paste Values).
- Consider Power Query for one-time transformations as its engine is columnar and optimized for bigger datasets.
Conclusion
Calculating months between dates remains one of the highest-leverage date skills in Excel. Whether you choose the succinct DATEDIF, the transparent YEAR/MONTH arithmetic, or fractional solutions with YEARFRAC, you’ll prevent costly timing mistakes, speed up modeling tasks, and build spreadsheets colleagues trust. Continue exploring related date functions—EDATE, EOMONTH, and WORKDAY—to solidify your time-based analytics toolkit. Start applying these methods today, and watch your operational and financial models gain both accuracy and credibility.
Related Articles
How to Show the 10 Most Common Text Values in Excel
Learn multiple Excel methods to list the 10 most frequent text values—complete with step-by-step examples, business use cases, and expert tips.
How to Abbreviate Names Or Words in Excel
Learn multiple Excel methods to abbreviate names or words with step-by-step examples and practical applications.
How to Abbreviate State Names in Excel
Learn multiple Excel methods to abbreviate state names with step-by-step examples, professional tips, and real-world applications.