About dateTime creation

Here is a leason learned about dateTime creation. I am still struggling if this is a bug or not, so I like comments. At least it is something I did not expect hence this post. Here is the microflow I used to generate a date: This microflow creates a date with the command dateTime(2011,1,1) for the first of january. I then check do see if I already have this date in de database. If not I create it and then do something with it otherwise I update the date, check if I am on todays date, add a day to the day variable and start over. The problem lies in the statement dateTime(2011,1,1). From the documentation one can learn that it uses the server calender and should return "Mon Jan 01 00:00:00 CET 2011". The reality is a bit different. In postgres the date will be 2010-12-31 22:00:00 and the view in Mendix will be 31-12-2010 23:00. Furthermore the date creation will go wrong in march because it will go from 26-03-2011 23:00 to 28-03-2011 00:00 when DST kicks in. I still wrestle with it if this is a bug or not. From a programmer point of view when I create a dateTime(2011,1,1) I would expect 01-01-2011 00:00 and not 31-12-2010 23:00 because of the timezone of the server. My lesson learned is to use dateTime(2011,1,1,0,0,0) when creating dates. But I really like to know what you think about this subject. Should I have foreseen this flow going wrong? Or should DST not been taken into account by the Mendix program when I do a date creation with less than six parameters?
1 answers

I'm afraid the documentation for 3.x is incorrect here, the dateTime function uses the timezone of the session of the user and the dateTimeUTC function uses UTC as a timezone. If you are doing this in a scheduled event (with the system session), it will use UTC as a timezone. In 3.x we have made sure that the timezone the server is running in is irrelevant for everything but scheduling events at a certain time. In our opinion the location of the server in the world should not affect anything else. For more information on date and time handling in 3.0, see https://world.mendix.com/display/refguide3/Date+and+Time+Handling+in+3.0

I will update the documentation for 3.x accordingly. Do note you were linking to the 2.5 documentation though, I won't update this version because the text is correct there.

Edit: updated documentation is here: https://world.mendix.com/display/refguide3/Date+creation

However there shouldn't be a difference between dateTime(2011,1,1,0,0,0) and dateTime(2011,1,1), if there is I recommend filing a ticket so we can have an in-depth look. I could not reproduce this myself.