Excel Find Closest Date: Exact Match & Nearest Date
To find the closest date in Excel, use the INDEX and MATCH functions with MIN(ABS(range - target)) to locate the nearest date before or after your target. This article explains the formula step by step, how to handle ties, and how to return the date or its position.
Why You Might Need This
Excel stores dates as serial numbers, so you can subtract dates to get the difference in days. When you need the nearest date from a list—say, the closest delivery date to a requested ship date, or the nearest holiday to a project deadline—a simple VLOOKUP won’t work because it only finds exact matches or the next smaller value. The array formula approach below finds the date with the smallest absolute difference, regardless of order.
The Core Formula
Assuming your list of dates is in A2:A100 and your target date is in B1, use:
=INDEX(A2:A100, MATCH(MIN(ABS(A2:A100-B1)), ABS(A2:A100-B1), 0))
Enter it as an array formula in older Excel (Ctrl+Shift+Enter). In Excel 365 and Excel 2021, it works normally due to dynamic arrays.
How it works:
ABS(A2:A100-B1)computes the absolute difference in days between each date and the target.MIN(...)finds the smallest difference, i.e., the closest.MATCH(MIN(...), ..., 0)returns the position of that smallest difference in the array.INDEX(A2:A100, position)returns the actual date at that position.
Returning the Difference in Days
If you need the number of days between the target and the closest date, use:
=MIN(ABS(A2:A100-B1))
That gives a positive number. To show whether the closest date is before or after the target, use a more complex formula with IF and INDEX, or use XLOOKUP in Excel 365.
Handling Ties and Order
If two dates are equally close (e.g., target is exactly between two dates), MATCH returns the first one in the list. To prefer the earlier date, you can sort the list ascending before applying the formula. To prefer the later date, sort descending. If you want the closest date that is strictly before or strictly after, use MAXIFS or MINIFS:
- Closest date before target:
=MAXIFS(A2:A100, A2:A100, "<="&B1) - Closest date after target:
=MINIFS(A2:A100, A2:A100, ">="&B1)
Using XLOOKUP (Excel 365)
In Excel 365, XLOOKUP can find the nearest with a simpler syntax:
=XLOOKUP(B1, A2:A100, A2:A100, , 1) // next larger (closest after) =XLOOKUP(B1, A2:A100, A2:A100, , -1) // next smaller (closest before)
But XLOOKUP doesn't give the absolute closest unless you sort the data. The array formula remains the most reliable for an unsorted list.
Common Mistakes
- Forgetting to press Ctrl+Shift+Enter in older Excel versions—this turns the formula into a regular formula and returns a #VALUE! error.
- Not using absolute references if you copy the formula down—use
$A$2:$A$100and$B$1. - Hidden blank cells—blanks are treated as 0, which can skew the MIN. Use
IFERRORor filter blanks. - Date formatting—ensure the target cell is a real date, not text. Use
DATEVALUEif needed.
Alternatives and Limitations
If you need the closest date within a specific range (e.g., only future dates), combine with IF:
=MIN(IF(A2:A100>=B1, ABS(A2:A100-B1)))
This is an array formula that ignores dates before the target. For very large datasets (10,000+ rows), the array formula can slow down; consider using a helper column with ABS(A2-B$1) and then MIN and MATCH on that column.
The formula works with dates only; if your list contains date-time values, the difference is in days and fractions, so the closest may be a few hours off. Round to whole days with ROUND if needed.
Frequently Asked Questions
How do I find the closest date to today?
Replace B1 with TODAY() in the formula. For example, =INDEX(A2:A100, MATCH(MIN(ABS(A2:A100-TODAY())), ABS(A2:A100-TODAY()), 0)). This updates automatically each day.
Can I return the row number of the closest date?
Yes, replace INDEX(A2:A100, ...) with MATCH(MIN(ABS(A2:A100-B1)), ABS(A2:A100-B1), 0) alone. That gives the position within the range (1 for the first cell). Add the starting row offset if needed.
What if my list has duplicate dates?
The formula returns the first occurrence in the list. If you need all occurrences, use FILTER in Excel 365 to return all dates where the absolute difference equals the minimum.
Does this work in Google Sheets?
Yes, the same array formula works in Google Sheets, but you don't need Ctrl+Shift+Enter—just press Enter. Use ARRAYFORMULA if needed for older sheets.
How do I find the closest date that is after a target?
Use MINIFS as shown above, or an array formula: =MIN(IF(A2:A100>=B1, A2:A100)). This ignores dates before the target and returns the smallest date that is greater or equal.
Why does my formula return a date like 1/0/1900?
That happens when the result is 0, which Excel displays as January 0, 1900. This usually means the target date is exactly equal to a date in the list, and the difference is 0—but the formula may be returning the wrong cell due to a range mismatch. Check that your ranges are identical in size.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.