Sub topic 9
What Happens When the Target Day Does Not Exist
This chapter assumes you can enter formulas, use cell references such as A2, and apply a number format. It also assumes you know that a date is a serial number (a count of days), and that EDATE moves a date by whole months. Here you will see what EDATE does when the destination month is too short to contain the original day. You will also see how that behavior causes drift in schedules and how to control it.
The problem
Months have different lengths. If you start on 31 January and move forward one month, February has no 31st. A program has three reasonable choices:
- Return an error.
- Spill over into the next month (31 February becomes 2 or 3 March).
- Stop at the last valid day of the target month.
EDATE takes the third choice. This is called month-end clamping: when the same day number does not exist in the target month, the result is the last day of that month.
The clamping rule
The rule has two parts. EDATE keeps the day number of the start date when it can. When the target month is shorter than that day number, it uses the target month's last day.
=EDATE(DATE(2024,1,31),1)This returns 29 February 2024, serial number 45351. The same start date in a non-leap year gives a different result:
=EDATE(DATE(2023,1,31),1)This returns 28 February 2023, serial number 44985. The formula is identical and only the year differs, so the leap-year calendar decides the answer.
Clamping applies to any day number that is missing from the target month, not only the 31st:
| Start date | Months | Result | Why |
|---|---|---|---|
| 31 Jan 2024 | 1 | 29 Feb 2024 | February 2024 has 29 days |
| 31 Jan 2023 | 1 | 28 Feb 2023 | February 2023 has 28 days |
| 30 Jan 2023 | 1 | 28 Feb 2023 | No 30th in February |
| 31 Mar 2024 | 1 | 30 Apr 2024 | April has 30 days |
| 31 Mar 2024 | -1 | 29 Feb 2024 | Negative months clamp too |
| 29 Feb 2024 | 12 | 28 Feb 2025 | 2025 is not a leap year |
| 29 Feb 2024 | 48 | 29 Feb 2028 | 2028 is a leap year, so the day exists |
The result is never an error and never spills into the next month. A valid start date always produces a valid date.
How the decision works
The following flowchart shows what EDATE does internally, in conceptual terms.
Contrast with building a date by hand
You can imitate EDATE with DATE, but DATE does not clamp. It carries extra days into the next month:
=DATE(2024,1+1,31)This asks for 31 February 2024. February 2024 has 29 days, so DATE counts 2 days past the end and returns 2 March 2024. The two approaches give different answers for the same intent:
| Formula | Result for a start of 31 Jan 2024 |
|---|---|
| `=EDATE(A2,1)` | 29 Feb 2024 |
| `=DATE(YEAR(A2),MONTH(A2)+1,DAY(A2))` | 2 Mar 2024 |
This is a common source of off-by-a-few-days errors. If a colleague replaced an EDATE with a DATE formula "to make it clearer," the results will differ in short months. Use EDATE when you want clamping. Use the DATE version only when you deliberately want overflow.
If you want to build the date by hand but still clamp, take the smaller of the two candidates:
=MIN(DATE(YEAR(A2),MONTH(A2)+1,DAY(A2)),EOMONTH(A2,1))The overflowed date is always later than the end of the target month, so MIN picks the month end exactly when the day does not exist. In practice, EDATE(A2,1) is shorter and does the same job.
Drift: why chaining months loses the day
Clamping is local to one call. It does not remember the original day. If you build a schedule by adding one month to the previous row, one clamped result changes every later row.
Suppose A2 holds 31 January 2024 and each row below adds one month to the row above:
=EDATE(A2,1)Fill this down from A3. The results are:
| Row | Chained: `=EDATE(previous,1)` | Anchored: `=EDATE($A$2,n)` |
|---|---|---|
| A2 (start) | 31 Jan 2024 | 31 Jan 2024 |
| n = 1 | 29 Feb 2024 | 29 Feb 2024 |
| n = 2 | 29 Mar 2024 | 31 Mar 2024 |
| n = 3 | 29 Apr 2024 | 30 Apr 2024 |
| n = 4 | 29 May 2024 | 31 May 2024 |
| n = 5 | 29 Jun 2024 | 30 Jun 2024 |
The chained column is wrong from March onward. After February clamps to the 29th, the formula has no way to know the start was the 31st, so every later date sticks to the 29th. This is drift.
The fix is to compute every row from the original date with a month counter. Put the start date in A2, the counters 0, 1, 2 and so on in column B, and this formula in column C:
=EDATE($A$2,B2)The dollar signs keep every row pointing at the original start date. Each row clamps independently, and the day is restored whenever the month is long enough. This is the anchored column in the table above.
Staying on the last day of the month
Sometimes the intent is "always the last day of the month", such as a billing date that falls on 28 February 2023 and should be 31 March next. EDATE cannot know this. From 28 February 2023, EDATE(...,1) returns 28 March, not 31 March.
Use EOMONTH when the start date is a month end. This formula chooses between the two behaviors:
=IF(A2=EOMONTH(A2,0),EOMONTH(A2,B2),EDATE(A2,B2))The test A2=EOMONTH(A2,0) is true only when A2 is already the last day of its month. In that case the result is the last day of the month B2 months away. Otherwise it behaves like a normal EDATE.
Before you apply it, decide which rule your process follows. A rent schedule that starts on the 30th, a subscription that renews on the "same day each month", and a statement that closes at month end are three different rules. Write the rule next to the formula so the next reader knows it is deliberate.
Related behaviors worth knowing
EDATEtruncates a fractionalmonthsargument, soEDATE(A2,1.9)moves one month.EDATEandEOMONTHreturn serial numbers, so you can subtract or compare their results like any other date.- If the start argument is text that Excel cannot read as a date, the result is
#VALUE!. Text dates are covered later in this tutorial. - Clamping applies to both directions. A negative
monthsargument can also land in a shorter month and clamp.
A short checking routine
Before you trust a month-based schedule, run these checks:
- Put 31 January 2024 in the start cell. Confirm February shows the 29th.
- Change the start to 31 January 2023. Confirm February shows the 28th.
- Confirm March shows the 31st again if the schedule is anchored, and the 28th or 29th if it is chained.
- Compare the last row with
=EDATE($A$2,n)for the same n. They must match.
Exercise
Cell A2 holds 30 November 2023. What does =EDATE(A2,3) return, and what does =EDATE(EDATE(EDATE(A2,1),1),1) return? Explain any difference.
Show answer
The first formula returns 29 February 2024. Moving three months from 30 November lands in February 2024, which has 29 days, so the 30th is clamped to the 29th. The nested formula returns 29 February 2024 as well here, because the first step gives 30 December 2023, the second gives 30 January 2024, and the third clamps to 29 February. Both agree in this case because only the last step clamps. They would differ if an earlier step clamped. For example, starting on 31 December 2023 and moving by 2 months gives 29 February 2024, while stepping one month at a time gives 31 Jan, then 29 Feb, which is the same. A difference appears only when a clamped date is then moved onward, such as 31 January then 29 February then 29 March, compared with 31 March from =EDATE(A2,2).
Exercise
A schedule starts on 31 August 2024 in A2 and uses =EDATE(previous row,1) for each later row. What date does the third row after the start show, and what should it be if the schedule is meant to fall on the 31st whenever possible? Give a corrected formula.
Show answer
The chained rows are 30 September 2024, 30 October 2024 and 30 November 2024, so the third row shows 30 November. With the 31st preferred, October has 31 days, so the second row should be 31 October, and the third row, 30 November, is correct only by coincidence of November's length. The error appears in the second row, which shows 30 October instead of 31 October. The corrected formula anchors to the start date with a month counter n in column B: =EDATE($A$2,B3). For n = 2 this returns 31 October 2024.