Sub topic 13
Practical patterns: due dates, month ranges, age and tenure
This chapter assumes you know how Excel stores dates as serial numbers and how TODAY, EDATE, EOMONTH and DATEDIF behave on their own. Here you combine them into formulas you can reuse.
Choose the right tool
Due dates
For payment terms of a fixed length, add days to the invoice date in A2:
=A2+30For a monthly schedule, such as a subscription that renews on the same day each month, use EDATE:
=EDATE(A2,1)If the terms say "end of the following month", use EOMONTH:
=EOMONTH(A2,1)To flag a due date in B2, compare it with today. Because TODAY is volatile, the result changes whenever the workbook recalculates:
=IF(B2<TODAY(),"Overdue",B2-TODAY()&" days left")Month ranges
A report for the month containing A2 needs a first and last day. The two formulas share one idea: EOMONTH finds a month end, and adding 1 to the previous month end gives the first day.
=EOMONTH(A2,-1)+1=EOMONTH(A2,0)The number of days in that month is the difference between the two month ends. For 10 February 2024 in A2, this returns 29:
=EOMONTH(A2,0)-EOMONTH(A2,-1)To test whether a date in C2 falls inside the month of the date in E1, compare it against both boundaries. This version also works when C2 holds a time of day:
=AND(C2>=EOMONTH(E1,-1)+1, C2<EOMONTH(E1,0)+1)Age and tenure
With a start date in A2, DATEDIF joins complete years with the leftover complete months:
=DATEDIF(A2,TODAY(),"Y")&" years, "&DATEDIF(A2,TODAY(),"YM")&" months"This returns #NUM! if A2 is later than today. A guard avoids the error:
=IF(A2>TODAY(),"",DATEDIF(A2,TODAY(),"Y")&" years, "&DATEDIF(A2,TODAY(),"YM")&" months")You can check the logic with fixed dates. From 15 August 2020 to 10 March 2024, there are 3 complete years. The remainder runs from 15 August 2023 to 10 March 2024. That is 6 complete months, because 10 March is before the 15th.
=DATEDIF(DATE(2020,8,15),DATE(2024,3,10),"Y")&" years, "&DATEDIF(DATE(2020,8,15),DATE(2024,3,10),"YM")&" months"This returns 3 years, 6 months.
Common mistakes in combined formulas
| Mistake | Effect | Fix |
|---|---|---|
| Using `"MD"` to get leftover days | Can return wrong or odd values | Subtract `EDATE(A2, whole months)` from the end date |
| Hardcoding a "today" date | Result never updates | Use `TODAY()` where you want live values |
| Comparing timestamps to a month end | Last day's rows are dropped | Compare with `<EOMONTH(...)+1` |
| Text dates such as `"2024-03-01"` | Arithmetic fails or gives #VALUE! | Convert with `DATE` or `DATEVALUE` |
Exercise
Dates are in column A, and the first day of the month is needed in B and the last day in C. Write both formulas for row 2. Then say how many days the month of 20 February 2023 has, using one formula.
Show answer
B2: =EOMONTH(A2,-1)+1. C2: =EOMONTH(A2,0). Days in month: =EOMONTH(A2,0)-EOMONTH(A2,-1). For 20 February 2023, EOMONTH(A2,0) is 28 February and EOMONTH(A2,-1) is 31 January, so the result is 28.