Month Diff in Excel: How to Calculate Months Between Dates
In this article
To find the difference in months between two dates in Excel, the most efficient method is using the =DATEDIF(start_date, end_date, "m") formula. This function calculates the total number of complete months that have elapsed between the start date and the end date. For example, if your start date is in cell A2 and your end date is in cell B2, the formula =DATEDIF(A2, B2, "m") will return the integer count of full months between those two points in time.
What You'll Need
- A computer with Microsoft Excel installed (works in all modern versions including Excel 365, 2021, 2019, and 2016).
- A dataset containing at least two columns of dates (e.g., a "Start Date" column and an "End Date" column).
- Dates formatted as actual Date values in Excel, not as plain text.
Step-by-Step
- Prepare Your Data: Ensure your dates are entered in a way that Excel recognizes. Enter your start date in cell A2 (e.g., 01/15/2023) and your end date in cell B2 (e.g., 05/20/2024). If the dates are aligned to the right of the cell by default, Excel recognizes them as dates. If they are aligned to the left, they may be stored as text and will cause the formula to fail.
- Select the Target Cell: Click on the cell where you want the result to appear (for example, cell C2).
- Enter the DATEDIF Formula: Type the following exactly:
=DATEDIF(A2, B2, "m"). Note thatDATEDIFis a "hidden" function in Excel; it will not appear in the formula autocomplete dropdown as you type, but it is fully functional. - Understand the Arguments:
- Start_date: This is the earlier date. If the start date is later than the end date, Excel will return a #NUM! error.
- End_date: This is the later date.
- Unit: The "m" tells Excel to return the difference in complete months.
- Press Enter: Once you hit Enter, Excel will display the total number of full months. Using the example of Jan 15, 2023, to May 20, 2024, the result would be 16.
- Apply to Other Rows: To calculate the month difference for an entire list, hover your mouse over the bottom-right corner of cell C2 until the cursor turns into a small black cross (the Fill Handle). Click and drag the handle down to the bottom of your data range.
- Verify the Result: Double-check a few rows manually. Remember that
DATEDIFonly counts completed months. If the start date is January 15 and the end date is February 14, the result will be 0 because a full month has not yet elapsed.
Common Mistakes
One of the most frequent errors is swapping the order of the dates. The DATEDIF function requires the start date to come first. If you put the more recent date in the first argument, you will see the #NUM! error. Always ensure your formula follows the chronological order of time.
Another common mistake is using the wrong unit code. While "m" provides the total months, some users mistakenly use "y" (which gives total years) or "d" (which gives total days). There are also specialized codes like "ym", which calculates the number of months excluding the years. For example, if the difference is 14 months, "m" returns 14, but "ym" returns 2 (the remainder after subtracting the full year).
Users also frequently forget the quotation marks around the unit. Writing =DATEDIF(A2, B2, m) without quotes will result in a #NAME? error because Excel thinks "m" is a named range rather than a text instruction.
Finally, formatting the result cell as a "Date" is a common pitfall. Because the result of the formula is a number (the count of months), the cell should be formatted as "General" or "Number". If the result cell is formatted as a date, a result of "12" might appear as "January 12, 1900", which is confusing and incorrect.
Tips
If you need a more precise calculation that includes fractions of a month (e.g., 16.5 months), DATEDIF cannot do this because it only returns integers. Instead, use a subtraction formula combined with the YEARFRAC function. The formula =YEARFRAC(A2, B2) * 12 will give you the difference in months as a decimal, providing a much more granular view of the time elapsed.
For those who want to calculate the difference between the calendar months regardless of the day of the month (e.g., January 31 to February 1 counting as one month), you can use a mathematical approach: =(YEAR(B2)-YEAR(A2))*12 + MONTH(B2)-MONTH(A2). This ignores the specific day and simply looks at the month and year values.
To make your spreadsheet more readable, you can concatenate the result with text. Use the formula =DATEDIF(A2, B2, "m") & " Months" to make the cell display "16 Months" instead of just "16".
Troubleshooting
If your formula returns #VALUE!, the most likely cause is that one of your dates is not actually a date. Excel stores dates as serial numbers. If a date was imported from another software, it might be stored as text. To fix this, select the column of dates, go to the Data tab, select Text to Columns, click Next twice, and in the Column data format section, select Date and choose the correct format (e.g., MDY). Click Finish to convert the text to real dates.
If you see #NUM!, check your date order. Ensure the date in the first argument is earlier than the date in the second argument. If your data is sorted in descending order (newest to oldest), you will need to flip the cell references in your formula.
If the result seems off by one month, remember that DATEDIF is strict. It only counts a month once the day of the month in the end date is equal to or greater than the day of the month in the start date. If you need to "round up" any partial month to a full month, you can add one day to your start date or end date within the formula, or use the ROUNDUP function in conjunction with YEARFRAC.
Frequently Asked Questions
Why doesn't DATEDIF appear in the Excel formula list?
DATEDIF is a legacy function kept for compatibility with Lotus 1-2-3. Microsoft does not officially document it in the formula autocomplete list, but it works in all versions of Excel. You must type the entire function name manually.
How do I calculate months between a date and today?
You can replace the end_date argument with the TODAY() function. The formula would be =DATEDIF(A2, TODAY(), "m"). This is useful for tracking the age of an account or the duration of an ongoing project.
What is the difference between "m" and "ym"?
The "m" unit returns the total number of months between two dates (e.g., 25 months). The "ym" unit returns the number of months remaining after subtracting full years (e.g., 1 month), which is useful for saying "2 years and 1 month".
Can I use this to calculate work-months?
No, DATEDIF calculates calendar months. If you need to calculate working days or business months, you should use the NETWORKDAYS function to find the total working days and then divide by your average working days per month (usually 20 or 21).
Does this work in Google Sheets?
Yes, the DATEDIF function uses the exact same syntax and arguments in Google Sheets as it does in Microsoft Excel.
How do I handle empty cells in my date columns?
If a cell is empty, DATEDIF may return a very large number or an error because Excel treats an empty cell as day 0 (January 0, 1900). To prevent this, wrap your formula in an IF statement: =IF(OR(A2="", B2=""), "", DATEDIF(A2, B2, "m")).