Number of Months Between Two Dates in Excel Without DATEDIF
In this article
To calculate the number of months between two dates in Excel without using the DATEDIF function, use the formula: =(YEAR(end_date)-YEAR(start_date))*12 + MONTH(end_date)-MONTH(start_date). This method calculates the mathematical difference between the years (multiplied by 12) and adds or subtracts the difference between the month integers to find the total elapsed months.
While DATEDIF is a popular legacy function, it is "hidden" in modern Excel versions—meaning it does not appear in the formula autocomplete list and is not officially documented in the function library. Using a combination of YEAR and MONTH functions is more transparent, easier to audit, and works consistently across all versions of Excel, including Excel for the Web and Google Sheets.
What You'll Need
- A spreadsheet containing two valid dates (a start date and an end date).
- Basic knowledge of how to enter a formula into an Excel cell.
- Cells formatted as "Date" for the inputs and "General" or "Number" for the result.
Step-by-Step
- Organize Your Data: Place your start date in one cell (e.g., cell A2) and your end date in another cell (e.g., cell B2). Ensure these are recognized by Excel as dates and not as text.
- Select the Result Cell: Click on the cell where you want the total number of months to appear (e.g., cell C2).
- Enter the Year Difference: Type
=(YEAR(B2)-YEAR(A2))*12. This part of the formula finds how many full years have passed and converts them into months. For example, if the dates are in 2023 and 2025, this results in 24 months. - Add the Month Difference: Append
+ MONTH(B2)-MONTH(A2)to the formula. This adjusts the total based on the specific months of the year. If the start date is in December and the end date is in January, this will subtract 11 months from the year total to provide the correct count. - Complete the Formula: Your final formula in cell C2 should look like this:
=(YEAR(B2)-YEAR(A2))*12 + MONTH(B2)-MONTH(A2). Press Enter. - Format the Result: If Excel automatically formats the result cell as a date (showing something like "January 1900"), go to the Home tab, find the Number group in the ribbon, and change the dropdown menu from "Date" to "General" or "Number".
Common Mistakes
- Incorrect Cell Referencing: Swapping the start and end dates in the formula will result in a negative number. Always subtract the start date from the end date.
- Wrong Cell Formatting: The most common issue is the result cell being formatted as a date. Because Excel stores dates as serial numbers, a result of "5" might be displayed as "January 5, 1900". Always ensure the output cell is set to General or Number.
- Assuming Day-Level Precision: This specific formula calculates the difference between the calendar months. For example, if the start date is January 31 and the end date is February 1, this formula will return "1" because it only looks at the month and year integers, regardless of the day of the month.
- Using Text Instead of Dates: If your dates are typed as "Jan 2023" without a specific day, Excel may treat them as text strings. The YEAR and MONTH functions only work on valid date serial numbers.
Tips
- Handling Partial Months: If you need to account for the day of the month (i.e., you only want to count a month if a full 30 days have passed), you can wrap your formula in an IF statement or use the
DAYSfunction to check if the day of the end date is less than the day of the start date. - Absolute References: If you are comparing a list of multiple dates against one single "cutoff date," use absolute references (e.g.,
$B$2) for the cutoff date so you can drag the formula down the column without the reference shifting. - Rounding: If you use a different division-based method (like dividing the total days by 30.44), use the
ROUNDorINTfunction to avoid long decimals.
Troubleshooting
If the formula does not go to plan, try these steps in order:
- Check for #VALUE! Errors: This almost always means one of your dates is actually text. To test this, use the formula
=ISNUMBER(A2). If it returns FALSE, you must convert your text to a date using the "Text to Columns" tool or by re-typing the date. - Verify Date Order: If you get a negative number, ensure your end date is in the first part of the subtraction and the start date is in the second.
- Clear Formatting: If the result looks like a date or a weird symbol, select the cell, go to the Home tab, and select Clear > Clear Formats, then set the number format to "General".
- Check for Hidden Spaces: If your dates were imported from another software, there may be leading or trailing spaces. Use the
=TRIM()function to clean the cells before applying the month calculation.
Frequently Asked Questions
Does this formula count the partial month at the end?
No. This formula calculates the difference between the month and year integers. It does not look at the specific day of the month, so it treats any day in January and any day in February as being one month apart.
Can I use this formula for dates in different centuries?
Yes. The YEAR function handles any valid date recognized by Excel, so it will accurately calculate the difference between 1920 and 2024.
Why is my result showing as a date instead of a number?
Excel often tries to be helpful by copying the formatting of the cells referenced in a formula. Since you referenced date cells, Excel formats the answer as a date. Change the cell format to "General" to see the actual number of months.
Is this more accurate than dividing total days by 30?
Yes. Dividing by 30 or 30.44 provides an estimate. Using the YEAR and MONTH functions provides the exact calendar month difference, which is usually what is required for billing, employment, or age calculations.
Will this work in Google Sheets?
Yes. The YEAR and MONTH functions are standard across almost all spreadsheet software, including Google Sheets and LibreOffice Calc.