Return One Month Instead of 31 Days in an Excel Formula
Question details
Calculate a date range so a 31-day range returns 1 month and shorter ranges return their day counts.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet has start and end dates, such as March 31 and April 30, and needs a result based on the length of the range.
- Observed behavior
- The desired result is 1 for the 31-day range when both dates are counted, and the number of days for shorter ranges.
Enter the start date in E17 and the end date in F17 as recognized Excel dates, with the end date on or after the start date. Decide whether to count both dates: March 31 through April 30 is 31 days inclusive, but 30 elapsed days.
Count both dates and return 1 for ranges over 30 days
Use this formula when the start and end dates both count toward the day total.
Type the start date in E17 and the end date in F17.
Select the result cell and enter =IF(DATEDIF(E17,F17,"d")+1>30,1,DATEDIF(E17,F17,"d")+1).
Press Enter. March 31 through April 30 returns 1; a shorter inclusive range returns its day count.

Count elapsed days between the dates
Use the accepted formula when the start date should not be included in the day count.
Calculate the same date-range result in WPS Spreadsheets
Use WPS Spreadsheets to enter the inclusive-day formula and return 1 for ranges over 30 days while keeping shorter day counts.
- 1. Open your spreadsheet: Open WPS Spreadsheets and choose Open to select your workbook.
- 2. Enter the dates: Enter the start date in E17 and the end date in F17.
- 3. Add the formula: Select a result cell and enter =IF(DATEDIF(E17,F17,"d")+1>30,1,DATEDIF(E17,F17,"d")+1).
- 4. Calculate and save: Press Enter to calculate the result, then use File > Save to save the workbook.

Frequently Asked Questions
Why does March 31 through April 30 sometimes return 30 days?
DATEDIF(E17,F17,"d") counts elapsed days and does not include the start date. Add 1 to count both dates, giving 31 days for this range.
Does this formula calculate actual calendar months?
No. The formula returns 1 whenever the day count exceeds 30; it does not measure calendar months and also returns 1 for longer ranges.
What if the end date is earlier than the start date?
DATEDIF returns a #NUM! error. Check E17 and F17 and make sure the start date is on or before the end date.
How can I tell whether a result of 1 means one day or one month?
The numeric formula returns 1 in both cases. Use a separate label or modify the formula to return text such as "1 month" for ranges over 30 days.




