Discrepancy in the result of addDaysUTC function

Hi All,   I am using addDaysUTC function to determine future working date for my input date, but there are some discrepancies in the results. Issue explained below : Step 1 Input date : 28-10-2021 00:00:00  Result date = addDaysUTC (Input date, 2) = 30-10-2021 00:00:00 Step 2 Input date = Result date = 30-10-2021 00:00:00 Result date = addDaysUTC (Input date, 1) = 31-10-2021 00:00:00 Step 3 Input date = Result date = 31-10-2021 00:00:00 Result date = addDaysUTC (Input date, 1) = 31-10-2021 23:00:00   I have never ever seen this issue in the past. How is this possible that one function is giving different result for same formatted input date.  Does some already experienced this issue? Regards Abhinay
2 answers

DateTime handling is by definition quite a challenge.

DateTime attributes can be localized or non-localized. Also in the execution of logic depends on user, project and server timezone

See more details here: https://docs.mendix.com/refguide/datetime-handling-faq and https://academy.mendix.com/link/modules/374/lectures/3046/7.1-Introduction 


Apparently addDays doesn't add a day, it adds 24 hours, which causes a shift when we set time back one hour this weekend. Don’t bother with this. The first link Rene posted is in itself proof that datetimes are virtually impossible to work with. No doubt someone will tell you the described behavior is expected, while it’s just so very, very wrong.

You could try to cheat, using parseDateTime function like this:

parseDateTimeUTC(formatDateTimeUTC(addHours($YourDateVariable, 30-formatDateTimeUTC($YourDateVariable, 'HH')), 'dd-MM-yyyy') + ' ' + formatDateTimeUTC($YourDateVariable, 'HH:mm:ss'), 'dd-MM-yyyy HH:mm:ss')

This way you’re only changing the day number (and month and year, when necessary), not hours or minutes. There should be an easier way, but this is what I came up with just now.