Front-end time conversion from externel DB
Application Type
Reactive

We have build an application where we post records to an external DB coupled to OutSystems directly.
During this submit we are storing the creation DateTime. To ensure the time in the DB is correct for our timezone (because other systems are also directly looking into the DB), we are converting the CurrDateTime with ConvertFromUTC to our timezone before writing it to the DB. When looking at it directly through SQL tools or with aggregates the time is correctly. Only when we show it on our front-end as a DateTime, we see that it subtracts an hour.

This only occurs when we display it as a DateTime. If for example we put it in an InputField with type "text" it does  show the correct dateTime but with ugly format. As soon as we do any expression or DateTimeFormating it again substracts an hour.

Any idea?

If the place where the server is has a different timezone from the browser, the browser will adjust the timezone accordially.

Try to use this component in order to keep the timezone from the server: https://www.outsystems.com/forge/component-overview/2199/timezonereactiveutils

Regards

Gonçalo Almeida

Why is this adjustment only occurring when we display it as a DateTime? If we directly output it as a text it's un-adjusted.

Is there a way to cancel this adjusting process to ensure that we can still use the default OutSystems forms/expressions instead of needing to add the proposed component in between every form & expression to convert the DateTimes.

Kind regards,

Dieter

Hi @Dieter Vennekens

I would suggest storing DateTime in UTC then using the ConvertFromUTC when displaying the value. This way, DateTimes will always be displayed in the browser's timezone. 

-cezarF

Hello Cezar,

the issue with that approach is that when other systems read out the DB they will also need to convert the DateTimes. Therefor it's a hard requirement that the time in the DB is in our timezone.

Kind regards,

Hi Dieter, 

I'm afraid that this will become a technical debt that will eventually be needed to be fixed. 

On the different output between text input and datetime,  it must be the browser's auto conversion kicking in. Text input is rendered as <input type="text"... while the datetime could be <input type="datetime" ...

Have you tried  using FormatDateTime(value, "dd/MM/yyyy hh:mm:ss tt") ?

-cezarF

Indeed and we are trying to turn off this browsers auto conversion kicking in.

The formatDateTime first does the adjustment before doing the formating.

Dieter

How about doing the opposite when displaying by using ConvertToUTC and see how the browser would process it?

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