How to Return a Value When a Day Falls Between Two Dates in Excel
Question details
Create a dynamic Excel formula that identifies whether a recurring payment day falls within a specified date range and returns the appropriate amount.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Automating recurring payment schedules or conditionally calculating values based on whether a specific day of the month is within a predefined upper and lower limit.
- Observed behavior
- A dynamic logical formula is needed to test target dates against day limits and output a specific numerical value when the condition is met.
Ensure your target date cells are formatted correctly as Dates in Excel, and identify the specific lower and upper day limits you want to use for the calculation.
Use the MEDIAN and DAY Functions (Recommended)
This clever method uses the MEDIAN function to determine if a specific day falls between a lower and upper limit without needing complex nested IF statements.
The MEDIAN function returns the middle number in a set of values. By comparing the target day against the median of the target day, the lower limit, and the upper limit, we can logically deduce if the target day falls within the range.
Click on the cell where you want the returned payment amount to be displayed.
Type the formula: =(DAY(D$1)=MEDIAN(DAY(D$1),20,25))*20000. In this example, D$1 contains the target date, 20 is the lower day limit, 25 is the upper day limit, and 20000 is the return amount.
Replace the hardcoded numbers (20, 25, and 20000) with their respective cell references (e.g., A2, B2, C2) so the formula updates automatically when you change the limits or amount.
Press Enter. If you have a column of dates, drag the fill handle down to apply the formula to the rest of your dataset.

Use the IF and AND Functions
A more traditional and widely recognized approach using the IF and AND functions to verify if the day is strictly greater than the start day and less than the end day.
Easily Calculate Date Ranges with WPS Spreadsheet
WPS Spreadsheet fully supports advanced date and logical functions including MEDIAN, DAY, IF, and AND. You can seamlessly execute complex payment tracking, conditional logic, and data analysis using the exact same formulas.
- 1. Open your workbook in WPS Spreadsheet: Launch WPS Office and open the file containing your date and payment data.
- 2. Select the formula destination: Click the cell where you want the returned value to appear.
- 3. Enter the date checking formula: Input your preferred formula, such as =(DAY(D$1)=MEDIAN(DAY(D$1),20,25))*20000.
- 4. Press Enter to calculate: Hit Enter. You can then use the drag-fill handle at the bottom right of the cell to copy the formula to other rows.

Frequently Asked Questions
Why does the MEDIAN formula multiply by the payment amount?
In Excel, logical statements result in TRUE or FALSE. When used in a math operation, TRUE evaluates to 1 and FALSE to 0. Multiplying the logical test `(DAY(D$1)=MEDIAN(...))` by your amount returns the full amount if the condition is met (1 * amount), and 0 if it is not (0 * amount).
Can I use exact dates instead of just days of the month?
Yes. If you want to check full dates instead of just the day number, simply omit the DAY function and compare the actual date cells directly. For example: `=IF(AND(D1>=Start_Date, D1<=End_Date), Amount, 0)`.
What if my date range crosses into the next month?
If your recurring period spans across the end of a month (for example, from the 25th of one month to the 5th of the next), the standard MEDIAN or AND logic will fail because 5 is not greater than 25. In this scenario, you should use an IF statement with an OR condition, like `=IF(OR(DAY(D1)>=25, DAY(D1)<=5), Amount, 0)`.




