DateTime variables changes when passed from client to server.

DateTime variables changes when passed from client to server.



In our mobile app we have a flow where we selecting data from database based on user current time. As mentioned in this thread :
Builtin functions such as CurrDateTime() will return the date and time from the device when they are used in the client context (either in the UI or in a client action). If they're called in a server action they will return server date and time.

However if I create a DateTime type variable and set it to CurrDateTime() client side and then pass this variable as input parameter to server action the server action still using server time. 

So if I print the variable using client side action with console.log() for example and debug server side with the same variable as input parameter I have difference 1 hour between this same variable (Difference between my local time and server time - Lisbon). 

If I add additional step to conversion dateTime to text and pass variable to server action as a text and then reconvert back from text to date time - the value is correct.

It seems very strange default behavior to convert DateTime variables automatically. At least there should be a warning or built in conversion function with parameter to control if we want or not  to perform autocorrection of the time.

Thank  you.

Hi Mykola,

There is no conversion taking place (and that is the problem). Device timezone and server timezone are not part of the Date Time information, and as such you cannot compare them without conversion.

You may consider using the TimezoneMobileUtils component to perform any required timezone conversions.

Hi Mykola,

I made a small test and everything works as expected in my mobile (using OutSystems Now) as well as in Browser preview.

I'm sending a small module so you can test it and see if you still get one hour difference or if it works as it is expected?

But I would say that no conversion is made.

Eduardo Jauch

P.S. Are you doing any kind of "serialization/deserialization" using JSON?

Hi Eduardo,

Thank you very much for sharing the oml and it has same problem as I had on our app.

Jorge, I will take a look into proposed component - thank you.

Hello Mykola,

I did some more tests.
First I thought it could be a "bug" in data visualization, but it isn't.

What is happening is an automatic conversion from the hour being sent to the server and the hour of the server, based in the difference between the timezones. 

This conversion is made both when sending as well as when retrieving the Date Time from the server. 

So, if I send a date time with 14h from Portugal to the server (personal), that is -1h, it will store in server database as 13h, when I get from server, it will convert again to 14h.

This is not what I was expecting... 

Eduardo Jauch

I was not expecting, but it is the expected behavior:

CurrDateTime()In client-side calls, it returns the device date and time.
In server-side calls, it returns the platform server date and time.
In query calls, it returns the platform server date and time.

Date times in the device are converted in the server to the server time zone.
Likewise, date times in the server are converted to the server time zone.


There is an obvious mistaken as it should state that it is converted back in the device.


This does not happen when you send only the TIME (in a variable of type Time).