https://bugs.documentfoundation.org/show_bug.cgi?id=173740

--- Comment #2 from [email protected] ---
That sounds like a reasonable alternative to extending DATEDIF itself, and I
would be happy for this enhancement to evolve in that direction.

However, after looking at the implementation of the suggested alternative
functions, there is an important detail: the current `MONTHS(...;0)` and
`YEARS(...;0)` calculations themselves have some of the same end-of-month /
leap-day issues that motivated this enhancement.

For example, `getDiffMonths()` currently calculates the month difference and
then does essentially:

```cpp
if (nDay1 > nDay2)
    nRet -= 1;
```

so:

```text
MONTHS(31-May-2026; 30-Jun-2026; 0)
```

also returns 0, i.e. the same end-of-month case discussed in bug 172789.

`MONTHS(...;1)` returns the difference in calendar months, which gives 1 in
that case, but it is not equivalent to "complete months": for example 31-May to
1-Jun is also one calendar month apart.

Similarly, `YEARS(...;0)` is implemented from the month interval and therefore
inherits related edge cases, while `YEARS(...;1)` means calendar years rather
than complete elapsed years.

So I think your suggestion of extending the existing non-legacy functions may
actually be the cleaner design, but new `Type` values would be needed rather
than simply recommending the existing modes.

For example, conceptually:

```text
MONTHS(StartDate; EndDate; 2)
```

could mean correctly calculated complete months, using end-of-month adjustment
rather than only comparing the day numbers.

Additional modes could potentially cover the `"ym"` semantics as well.

Likewise, `YEARS()` could gain a corrected complete-years mode, and an
appropriate non-legacy day-difference function could be extended to cover the
`"md"` and `"yd"` remainder semantics.

I am not attached to putting the new mode in DATEDIF itself. My main goal with
this enhancement is to provide concise, reliable equivalents for all six useful
DATEDIF operations without changing the historical DATEDIF behaviour.

If extending MONTHS / YEARS / an appropriate day-difference function is
considered preferable, I would support changing the scope of this enhancement
accordingly.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to