In this example, the goal is to check if a given date is between two other dates, labeled "Start" and "End" in the example shown. For convenience, both start (E5) and end (E8) are named ranges. If you prefer not to use named ranges, make sure you use absolute references for E5 and E8.
Excel dates are just large serial numbers and can be used in any numeric calculation or comparison. This means we can simply compare a date to another date with a logical operator like greater than or equal (>=) or less than or equal (<=).
The main task in this example is to construct the right logical test. The first comparison is against the start date. We want to check if the date in B5 is greater than or equal (>=) to the date in cell E5, which is the named range start:
The second expression needs to check if the date in B5 is less than or equal (<=) to the end date in cell E5:
The goal is to check both of these conditions are TRUE at once, and for that, we use the AND function:
=AND(B5>=start,B5<=end) // returns TRUE or FALSE
The AND function will return TRUE when the date in B5 is greater than or equal to start AND less than equal to end. If either test fails, the AND function will return FALSE. We now have the logic we need to use with the IF function.
We start off by placing the expression above inside the IF function as the logical_test argument:
Next, we add a value_if_true argument. In this case, we want to return an "x" when a date is between two dates, so we add "x" as a text value:
If the date in B5 is not between start and end, we don't want to display anything, so we use an empty string ("") for value_if_false. The final formula in C5 is:
As the formula is copied down, the formula returns "x" if the date in column B is between the start and end date. If not, the formula returns an empty string (""), which looks like an empty cell in Excel. The values returned by the IF function can be customized as desired.