7
Views
5
Comments
Mobile device Client time
Question
Application Type
Mobile

I need to send the DateTime() of the mobile device to a database, but I always get the UTC time. I even tried addhours(CurrDateTime(),-4) and it does not work. How can I capture the dateTime of the device itself?

Rank: #67

Hi Gonzalo,


Dates on mobile and reactive applications are displayed in the client timezone and on the database it is usually saved in UTC but they are the same date, they are just presented in the timezone of the client.

If you get the date from the application (the one in UTC) and show it in the same device, it will be again displayed in the client timezone.

The important is that dates are always saved in the same timezone in the database (usually in UTC).


Being that said, is there any other specific reason for you to want to save the date in the database in a different timezone than UTC?


Regards,
João

Rank: #15845

João,


Thanks for your reply. But I just ran a test again and while the time in my device is 4pm, the record in my database shows 8pm.


Rank: #15845

João

I have a scrip that picks the record from the database and creates an email that says: we ran this transaction at XXX (datetime). So I figured that if I store CurrDateTime() - 4 hors in the database, this would solve the problem. But when I try to force that, the system still stores the server time.


Rank: #67

Hi Gonzalo,


The date in your database and on server side is UTC, so the one with -4 hours.

When you display it in client side, it gets automatically converted to the client timezone, so in your timezone, it will appear the one you expect. I am in UTC + 1, so in my device it would appear -3 hours according to what you expect.

When you send an email, you're sending it from the server, there is no client side. In that case, the date is indeed in UTC. In that case, you need to convert it to the timezone you want. The TimeZone component provides server-side actions for converting a date time to a timezone of your choice.


Regards,
João

mvp_badge
MVP
Rank: #17

Hi Gonzalo,

See the second solution of this article for explanation on how time is handled client side.

https://www.outsystems.com/forums/discussion/23160/mobile-currdate-and-currdatetime/

Regards,

Daniel