I hope someone else comes along to explain why this makes sense, but my two cents (without checking though) is that it has to do with DST and the fact that addMonths fails to take into account that time will shift an hour in two weeks. If you wait two weeks it will probably work until end of November. Maybe you could try something like this: trimToDaysUTC(addMonthsUTC(addHours($YourDateInput, 2), 4))
Edit: I checked, but I can’t reproduce the problem, so I’m at a loss here. Sorry for the noise. Only thing I noticed is that the result date will be rounded down when a day does not exist. So if you do January 30th + 1 month, you get February 28th as there are no more days in February. That makes sense though, so I assume your issue is not with that.
For those struggling with datetime functions: https://mydemoversion8-sandbox.mxapps.io/p/addtodatetime. This shows that the function can function fine:
So this raises the question: what makes Amol’s function misbehave?
A workaround if all else fails, or just testing to find the reason for misbehaving: does this also happen when you take BeginOfMonth?