Sub topic 13
Practical patterns: due dates, month ranges, age and tenure
This chapter combines the date tools from earlier chapters into formulas you can reuse. It assumes you know that Excel stores a date as a serial number, and that a date format only changes how the number is displayed. It also assumes you have met TODAY, EDATE, EOMONTH, and DATEDIF and can enter formulas with cell references.
Keep an as-of date in one cell
Most patterns below compare against today's date. Put that date in one cell instead of repeating TODAY() in every formula. In this chapter, $F$1 holds the as-of date.
=TODAY()Every formula then refers to $F$1. If you want to reproduce a report as it looked on a past date, or test an edge case, type a fixed date over the formula in $F$1. Nothing else needs to change.
Due dates
A due date is a start date plus a rule. The rule decides which function you need.
| Rule | Formula (start date in A2) | Result for 15 Jan 2024 |
|---|---|---|
| Net 30 days | `=A2+30` | 14 Feb 2024 |
| Same day next month | `=EDATE(A2,1)` | 15 Feb 2024 |
| End of this month | `=EOMONTH(A2,0)` | 31 Jan 2024 |
| End of next month | `=EOMONTH(A2,1)` | 29 Feb 2024 |
| 30 days after month end | `=EOMONTH(A2,0)+30` | 1 Mar 2024 |
Days are added with + because a day is one unit in the serial number. Months are not a fixed number of days, so they need EDATE or EOMONTH. Format each result cell as a date.
Overdue and due-soon status
With the due date in C2, subtracting gives a number of days. MAX stops the result from going negative.
=MAX(0,$F$1-C2)A status label can use the same comparison:
=IF(C2<$F$1,"Overdue",IF(C2-$F$1<=7,"Due soon","OK"))TODAY returns a whole number with no time fraction. An item due today is therefore not overdue until tomorrow. If the due dates contain times, such as 14 March 17:00, the comparison changes. Wrap the due date in INT(C2) to drop the time.
Recurring schedules: anchor on the first date
A schedule that adds one month to the previous row drifts. It also never recovers after a short month. Compare two ways of building a monthly schedule that starts on 31 January 2024:
| Row | Chained: `=EDATE(previous,1)` | Anchored: `=EDATE($A$2,n)` |
|---|---|---|
| 1 | 29 Feb 2024 | 29 Feb 2024 |
| 2 | 29 Mar 2024 | 31 Mar 2024 |
| 3 | 29 Apr 2024 | 30 Apr 2024 |
The chained version carries the clamped day of 29 forward. The anchored version always measures from the original date, so each row is clamped independently. Put the month count n in a helper column, or use ROW()-ROW($A$2), and keep the start date absolute.
=EDATE($A$2,B5)Month ranges
Reports often need the first and last day of the month containing a date. Both come from EOMONTH.
=EOMONTH(A2,-1)+1This is the first day of the month: the end of the previous month, plus one day.
=EOMONTH(A2,0)This is the last day of the month.
=EOMONTH(A2,0)-EOMONTH(A2,-1)This is the number of days in the month, the difference between two consecutive month ends.
Summing by month with a half-open range
Suppose column A has transaction dates and column C has amounts. A report cell E2 holds the first day of the month you want. The most reliable filter includes the first day and excludes the first day of the next month.
=SUMIFS($C:$C,$A:$A,">="&E2,$A:$A,"<"&EDATE(E2,1))This is safer than "<="&EOMONTH(E2,0). A transaction stamped 31 Jan 2024 15:30 has serial number 45322.6458. That is greater than the serial for 31 Jan, 45322, so the <= version silently drops it. The < version includes it.
Age and tenure
DATEDIF counts complete units. For an age or tenure label, combine two units:
=DATEDIF(A2,$F$1,"Y")&" years, "&DATEDIF(A2,$F$1,"YM")&" months""Y" counts complete years. "YM" counts the complete months left over after removing those years. The & operator joins the results into text, so the output is a label, not a number you can calculate with.
Guarding the formula
DATEDIF returns #NUM! when the start date is later than the end date. A blank start cell reads as 0, which gives an age of more than a century. A guarded version handles both cases:
=IF(OR(A2="",A2>$F$1),"",DATEDIF(A2,$F$1,"Y")&" years, "&DATEDIF(A2,$F$1,"YM")&" months")Leftover days without the MD unit
The "MD" unit is unreliable and can return wrong or negative-looking results around month ends. Compute leftover days by subtraction instead. Find the last complete-month anniversary with EDATE, then subtract it from the end date.
=$F$1-EDATE(A2,DATEDIF(A2,$F$1,"M"))Check it with a fixed example. The start date is 15 Aug 2019 and $F$1 is 10 Mar 2024.
| Measure | Formula | Result |
|---|---|---|
| Complete years | `=DATEDIF(A2,$F$1,"Y")` | 4 |
| Months after those years | `=DATEDIF(A2,$F$1,"YM")` | 6 |
| Total complete months | `=DATEDIF(A2,$F$1,"M")` | 54 |
| Last monthly anniversary | `=EDATE(A2,54)` | 15 Feb 2024 |
| Leftover days | `=$F$1-EDATE(A2,54)` | 24 |
The last row is 14 days left in February (29 − 15) plus 10 days in March. The result cell may display as a date because Excel copies the format of the referenced cells. Change its format to General to see 24.
Next anniversary and days remaining
The next anniversary is the start date shifted by one more year than the complete years so far:
=EDATE(A2,12*(DATEDIF(A2,$F$1,"Y")+1))Subtract $F$1 to get the days until then. For someone born on 29 February, EDATE returns 28 February in years that are not leap years. Decide whether your organization treats 28 February or 1 March as the anniversary before relying on this.
Contract end dates
A 12-month contract starting 1 March 2024 normally ends the day before the anniversary, so subtract one day:
=EDATE(A2,12)-1This returns 28 Feb 2025. For a one-month contract starting 31 Jan 2024, the same formula gives 28 Feb 2024, because EDATE clamps to 29 Feb first. If the contract wording says "to the end of the month", use EOMONTH(A2,0) instead. The clamping rule is arithmetic, not a legal definition, so confirm it against the agreement.
Defensive checks
All of these patterns break if a "date" is really text. A cell that looks like a date but is left-aligned is often text, and EDATE and DATEDIF return #VALUE! for it. Test before calculating:
=IF(ISNUMBER(A2),EDATE(A2,1),"Check date in A2")Also check these before trusting a result:
- Subtraction results are formatted as General, not as dates.
- Anchored schedules use
$A$2, not a relative reference. - Month-range filters use
>=the first day and<the next first day. - Leftover days come from subtraction, never from
"MD".
Exercise
Cell A2 holds the date 31 Oct 2024 and F1 holds 15 Jan 2025. Write a formula that returns the first day of the month after A2's month. Then write the formula for the number of complete months between A2 and F1, and give its result.
Show answer
First of next month: =EOMONTH(A2,0)+1, which returns 1 Nov 2024. Complete months: =DATEDIF(A2,F1,"M"). From 31 Oct 2024 to 15 Jan 2025 the result is 2: 30 Nov and 31 Dec are passed, but the 31 Jan anniversary is not reached.
Exercise
A monthly invoice schedule starts on 30 Nov 2023 in A2. A teammate fills down =EDATE(A2,1) from row 3 so each row shifts the row above. What date appears in row 5 (three months after the start), and what formula would give the correct date for that row?
Show answer
Chained: Dec 30, Jan 30, then Feb 29, so row 5 shows 29 Feb 2024 and every later row stays on the 29th. Anchored: =EDATE($A$2,3) returns 29 Feb 2024 for that row, and =EDATE($A$2,4) returns 30 Mar 2024. Row 5 matches, but rows after it do not, because the anchored version recovers the 30th while the chained one does not.
Exercise
A tenure formula shows #NUM! for one new hire whose start date is next month. Which part of the formula should you add to prevent this, and what should it return?
Show answer
Add a guard such as =IF(A2>$F$1,"",DATEDIF(A2,$F$1,"Y")&" years") so a future start date returns an empty string (or a message like "Not started") instead of letting DATEDIF fail.