Page shows one date earlier

Hi,   I have date attribute which is set to localize ‘no’. I manipulate that date in MF by adding date function(addMonthsUTC(date,4)). but it shows one date earlier to the page. We(User) uses default time-zone, it means , User Client and Server both are in same zone.    In short, how date traverses,   1. Read Date from entity (DB) in MF,  2.  In MF, we add 4 months to that date 3. pass that object to Page and Object renders that date property on the page. I tried with trim function and all. what would be the solution to resolve this. Note – This is not aconsistent behavior.
2 answers

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: 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?