415
Views
3
Comments
Solved
Date not displaying correctly in different Time Zone
Question
Application Type
Reactive

Hi,

We have an issue where dates entered through an OutSystems UI in IST zone are not displaying correctly in OutSystems UI in CST and MST zones.  The date is entered in the UI using a calendar widget.  Time is not captured.  The data is stored in the database as a datetime2 field.

The date is entered in IST as 01/01/2028 and displays on the UI in CST/MST zones as 12/31/2027.  Can anyone provide advise on how to resolve this issue?


Document with detail and screenshots is attached.


Thanks!

Dates.docx
2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

Hi Karen,

your problems all arise from using a datetime for storing a date.  If it is a date, then just use the date type.

When showing datetimes in a reactive ui, they are always automatically translated to the timezone of the user's device.  This is not a incorrect, this intentional behaviour.

For example, if you set a date of 01/01/2028 on a client in IST, an you use a datetime for this, by the time it gets to a server that is for example in CST timezone, it will be translated to 31/12/2027 18:30:00.  

If someone in CST later uses a UI to look at this date, it will be 31/12/2027.

referring to your examples: 

the orange one was entered in a timezone 5:30 hours ahead of server timezone (CST), so is stored after deducting 31/12 18:00 hours

the yellow ones were entered in timezone 6:00 hours behind of server timezone, so is stored as 01/01 06:00

the green one is entered 7:00 hours behind server timezone, so stored as 01/01 07:00

the white ones were loaded on server side, so stored as 01/01 00:00

All of the above is as intended by the platform, with the purpose of each person seeing in their ui data in relation to their local time.

For you, the solution is simple, don't use a datetime for a date.

Dorine

2023-10-21 19-42-11
Tousif Khan
Champion

Hello 

When you save the date time from the UI it , takes the date time input from the UI which is been displayed to you but in database it convert this to the Server time UTC , this is normal behaviour on reactive and mobile apps.  

But still if you want to save the date in such a way that it will display same everywhere, as you have selected on Ui then you have to use the attribute in db as text and save the date time in text format, or you need to use functions addhour() and add the number of hours to your time

If you will check this post it would be more clear to you  - 
https://www.outsystems.com/forums/discussion/75279/date-time-in-entity-and-ui-screen-different/

https://www.outsystems.com/forums/discussion/79113/my-input-datetime-different-with-database-datetime/

I hope this will help

Thanks
Tousif Khan

UserImage.jpg
Francisco Calderón

Hi Karen,

OutSystems handles date times by converting them to UTC before storing them in the server; whenever you are fetching data (e.g. in a screen) from the server, it will convert the data from UTC into the client's local timezone. This means that if the datetime was captured in IST, but later that data is fetched from a browser in CST, it will be converted to CST instead of IST, therefore showing what might appear as the wrong time.

This can be the source of your issue because the current local date might not line up with UTC's current date, which can lead to confusion in these cases. If you need to show the local Date when the event was captured, then you probably need to either store it in a dedicated Date field (without a Time element so that timezone offsets don't come into question), or somehow convert it back to the timezone where the event was first captured, though this probably involves additional logic/control fields such as tracking the timezone or UTC offset.

Hope that helps!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.