How to Use Excel Conditional Formatting for Dates Outside a 5 to 7 Month Window
Question details
The user needs to highlight dates that fall outside a specific 5-to-7-month window from a reference date using conditional formatting.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Setting up a conditional formatting rule to compare dates and highlight those falling outside a designated month timeframe.
- Observed behavior
- Using the DATEDIF function causes inaccurate results because it only counts complete months, failing to properly flag dates that are slightly more than seven calendar months apart.
Ensure your spreadsheet has a column of start dates and a corresponding column of end dates you wish to evaluate, and determine exactly which cell range needs the highlighting applied.
Use the EDATE and OR Functions for Conditional Formatting
This is the recommended method to accurately handle varying month lengths and leap years by calculating the exact calendar date limit instead of relying on whole-month counts.
The DATEDIF function often fails in this scenario because it truncates partial months, leading to incorrect highlights for edge-case dates. The EDATE function natively calculates exact dates based on a specified number of months in the future or past, making it perfect for comparing timeframes.
Highlight the range of dates you want to format. For example, select B1:B4 (assuming A1:A4 contains your starting reference dates).
Navigate to the 'Home' tab on the top ribbon, click on 'Conditional Formatting', and select 'New Rule' from the dropdown menu.
In the New Formatting Rule dialog box, click on 'Use a formula to determine which cells to format'.
In the formula bar, enter: =OR(B1<EDATE(A1,5),B1>EDATE(A1,7)). Ensure the cell references A1 and B1 correspond to the first row of your selected range.
Click the 'Format' button, navigate to the 'Fill' tab to pick a highlighting color, and click 'OK' twice to apply the rule.

Easily Apply Date Formatting with WPS Spreadsheet
WPS Spreadsheet fully supports advanced conditional formatting formulas, including EDATE, allowing you to easily track date windows without calculation errors.
- 1. Open your data in WPS Spreadsheet: Launch WPS Office, open your spreadsheet, and highlight the column containing the dates you need to format.
- 2. Access Conditional Formatting: Go to the 'Home' tab, click on 'Conditional Formatting', and select 'New Rule'.
- 3. Apply the Formula: Select the formula option, enter the EDATE formula for your 5-to-7-month window, pick a color, and save the rule.

Frequently Asked Questions
Why doesn't DATEDIF work properly for this 5-to-7-month conditional formatting?
DATEDIF only counts complete months. If two dates are exactly 7 months and a few days apart, DATEDIF may return an inaccurate whole number (e.g., 7 instead of reflecting it has passed the 7-month mark), causing dates just outside the window to be missed by the formatting rule.
What exactly does the EDATE function do in this formula?
The EDATE function calculates and returns the serial number of a date that is a specific number of months before or after a given reference date. It inherently accounts for different month lengths and leap years, making it highly reliable for calendar math.
Can I change the 5-to-7-month window to a different timeframe?
Yes. You can easily modify the numbers within the EDATE formula. For example, if you want a 3-to-6-month window, adjust the formula to =OR(B1<EDATE(A1,3),B1>EDATE(A1,6)).




