logo
search
Formula Errors

How to Use Excel Conditional Formatting for Dates Outside a 5 to 7 Month Window

Bushra ParveenBushra Parveen Sep 29, 2026 869 views

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.

How to Apply Excel Conditional Formatting for Dates Outside a 5-to-7-Month Window
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.
Before you start

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.

Solution 1Recommended

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.

1
Select the target date range

Highlight the range of dates you want to format. For example, select B1:B4 (assuming A1:A4 contains your starting reference dates).

2
Open Conditional Formatting settings

Navigate to the 'Home' tab on the top ribbon, click on 'Conditional Formatting', and select 'New Rule' from the dropdown menu.

3
Choose the formula option

In the New Formatting Rule dialog box, click on 'Use a formula to determine which cells to format'.

4
Enter the EDATE rule

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.

5
Apply a highlight format

Click the 'Format' button, navigate to the 'Fill' tab to pick a highlighting color, and click 'OK' twice to apply the rule.

Use the EDATE and OR Functions for Conditional Formatting
Relative Cell References: By not using dollar signs ($) in the cell references (e.g., A1 instead of $A$1), Excel will automatically evaluate each row dynamically down the selected column.
Powerful Spreadsheet Alternative

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. 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. 2. Access Conditional Formatting: Go to the 'Home' tab, click on 'Conditional Formatting', and select 'New Rule'.
  3. 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.
Fully supports advanced date calculation formulas like EDATE, DATEDIF, and OR.Seamless format compatibility with Microsoft Excel (.xlsx) files.Lightweight, fast, and features a familiar user interface for a zero-learning-curve transition.
microsoft office alternative - wps office

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)).