Sub topic 10
EOMONTH: last day of a month, and first-of-month tricks
This chapter assumes you can enter formulas, use cell references such as A2, and apply a number format to a cell. It also assumes you know that Excel stores a date as a serial number, a count of days, and that EDATE shifts a date by whole months. The work here builds on all three.
What EOMONTH does
EOMONTH(start_date, months) returns the serial number of the last day of a month. The month is found by moving months calendar months from the month that contains start_date.
start_dateis any valid date. Only its month and year matter. The day is ignored.monthsis a whole number.0means the same month,1the next month, and-1the previous month.
=EOMONTH(DATE(2024,1,15),0)This returns 45322, which is 31 January 2024. Format the cell as a date to see it that way.
Unlike EDATE, EOMONTH never keeps the original day number. It always lands on the final day of the target month. The result is a whole number with no time fraction, so it represents midnight at the start of that last day.
| `months` | Target month (start 15 Jan 2024) | Result | Serial |
|---|---|---|---|
| `-1` | December 2023 | 31 Dec 2023 | 45291 |
| `0` | January 2024 | 31 Jan 2024 | 45322 |
| `1` | February 2024 | 29 Feb 2024 | 45351 |
| `12` | January 2025 | 31 Jan 2025 | 45688 |
The 29 in the third row is not something you handle yourself. EOMONTH knows the length of every month, including February in leap years.
How it differs from EDATE
Both functions move by whole months. They answer different questions.
EDATEasks: what is the same day number, some months away? If that day does not exist, it clamps to the last day of the target month.EOMONTHasks: what is the last day of the month, some months away?
From 31 January 2024, =EDATE(DATE(2024,1,31),1) and =EOMONTH(DATE(2024,1,31),1) both return 29 February 2024. From 15 January 2024, EDATE returns 15 February and EOMONTH returns 29 February.
One subtle point: clamping makes EDATE lossy. Stepping 31 Jan to 29 Feb and then adding one more month gives 29 March, not 31 March. If you want month ends every month, use EOMONTH from the start so the day never drifts.
Edge cases in the arguments
- Fractional months are truncated.
monthsof1.9is treated as1. It is not rounded.-1.9is treated as-1. - Time of day is dropped. A
start_dateof 15 Jan 2024 at 18:00 gives the same result as 15 Jan 2024 at 00:00. - Invalid dates give
#VALUE!. This includes text that Excel cannot read as a date, and empty-string results from other formulas. - Out-of-range results give
#NUM!. The result must fall inside the supported date range. Moving far past the year 9999 fails. - Text that looks like a date may be accepted.
=EOMONTH("2024-01-15",0)often works, but the interpretation depends on your regional settings. Wrap uncertain text withDATEVALUE, or build the date withDATE, to avoid surprises. - Ranges are not accepted directly.
=EOMONTH(A2:A10,0)returns#VALUE!. The usual workaround is to coerce the range with=EOMONTH(A2:A10+0,0), or to fill the formula down one row at a time.
The first-of-month trick
Excel has no function that returns the first day of a month. You can derive it from EOMONTH, because the first day of a month is the day after the last day of the previous month.
=EOMONTH(A2,-1)+1Step by step, if A2 holds 17 June 2024:
EOMONTH(A2,-1)is the last day of May 2024, which is 31 May 2024.- Adding 1 gives 1 June 2024.
This works because dates are serial numbers, so +1 moves forward exactly one day. It handles every month length and year boundary. For 10 January 2024, the previous month end is 31 December 2023, and adding 1 gives 1 January 2024.
The same idea gives the first day of the next month:
=EOMONTH(A2,0)+1Common patterns
Days in a month
The last day's number is the length of the month:
=DAY(EOMONTH(A2,0))For any date in February 2024, this returns 29.
Days remaining in the month
=EOMONTH(A2,0)-A2On 17 June 2024 this returns 13, since June ends on the 30th. The current day is not counted.
End-of-month payment terms
Some invoice terms say "due at the end of the month after invoicing". With the invoice date in A2:
=EOMONTH(A2,1)An invoice dated 10 January 2024 is due 29 February 2024. An invoice dated 29 January 2024 is due on the same day.
A column of month ends
Put a starting date in A2. In B2 enter =EOMONTH(A2,0). In B3 enter:
=EOMONTH(B2,1)Fill down. Each row moves to the next month end, and none of them drift.
Current-month test with TODAY
To check whether a date falls in the current month, compare it to the boundaries. TODAY recalculates whenever the workbook does, so the result stays current.
=AND(A2>EOMONTH(TODAY(),-1), A2<EOMONTH(TODAY(),0)+1)The first condition means "after the previous month end". The second means "before the first day of next month".
Calendar quarter end
=EOMONTH(A2,MOD(3-MONTH(A2),3))For a date in February, MOD(3-2,3) is 1, so the result is the end of March. For a date in April, MOD(3-4,3) is 2, so the result is the end of June. For a date in March, the offset is 0 and the result stays in March. MOD returns a result with the sign of the divisor, so negative inputs still give a value from 0 to 2.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Result shows 45322 | The cell is formatted as General | Apply a date format |
| `#VALUE!` | Text date, blank string, or a range passed as `start_date` | Convert the data, or use `+0` for ranges |
| `#NUM!` | Result outside the supported date range | Check the `months` value |
| Timestamps missing from a month filter | Used `<=` against the month end | Compare with `< EOMONTH(...,0)+1` |
| Off by one in the first-of-month formula | Used `EOMONTH(A2,0)+1`, which is next month | Use `EOMONTH(A2,-1)+1` |
Exercise
Cell A2 holds the timestamp 20 Aug 2024 14:30. Write formulas that return (1) the first day of the month containing A2, (2) the first day of the next month, and (3) TRUE if the timestamp in B2 falls anywhere in the same month as A2, including the last day.
Show answer
(1) =EOMONTH(A2,-1)+1 returns 1 Aug 2024. (2) =EOMONTH(A2,0)+1 returns 1 Sep 2024. (3) =AND(B2>=EOMONTH(A2,-1)+1, B2<EOMONTH(A2,0)+1). The half-open range (start inclusive, next month's first day exclusive) keeps timestamps late on 31 Aug, such as 31 Aug 2024 23:59, inside the month.
Exercise
A2 holds 31 Jan 2024. What do =EDATE(A2,2) and =EOMONTH(A2,2) return, and why are they equal here but not for 15 Jan 2024?
Show answer
Both return 31 Mar 2024. EDATE keeps day 31, which exists in March, and EOMONTH returns March's last day, which is also 31. For 15 Jan 2024, EDATE(…,2) returns 15 Mar 2024 because it keeps the day number, while EOMONTH(…,2) still returns 31 Mar 2024.