243
Views
5
Comments
Solved
DateTime conversion
Question
Application Type
Reactive
Service Studio Version
11.54.75 (Build 63578)
Platform Version
11.30.0 (Build 43791)

In my client action, just received a datetime "2024-09-16T12:08:33Z" from a server action.
In my UI, I would like to show both the UTC time with the format "2024-09-16 12:08:33 PM" and exactly the same data I received from the server action as a text "2024-09-16T12:08:33Z".
Will show this data in ui using two expression.
I'm assigning the server action date to a UI text type variable and using DateTimeToText() to see the exact data, which is being converted to the local timezone time.

2020-07-21 19-28-50
Rajat Agrawal
Champion
Solution

Hi @Nour Hasan,

As per your issue,

1. What you can do what ever aggregate you are using inside that you should create one calculated attribute and convert your datetime into text data type there itself like below image.

And use calculated attribute to display DateTime.

Hope this helps you!!!


Regards,

Rajat

2024-07-09 06-45-01
Adarsh
Solution

In Outsystems, when you receive a DateTime from a server action, it is typically converted to the local timezone, which is why you're seeing a discrepancy between the UTC time and the original DateTime format.

To solve your problem to display the original DateTime exactly as received (without converting to local timezone):

Since you want to display the exact string as you received it ("2024-09-16T12:08:33Z"), you can store the original DateTime string directly in a Text variable and bind it to your UI expression.

Here’s how you can do it:

  1. In your client action, assign the exact string DateTime value from the server response directly to the Text variable (e.g., ServerDateText = "2024-09-16T12:08:33Z").
  2. Bind this text variable (ServerDateText) to an expression in the UI.

For displaying the UTC time in the required format:

To convert the DateTime to a specific format (e.g., "2024-09-16 12:08:33 PM") while keeping the UTC time, you can:

  1. Use DateTimeToText() function but first ensure the DateTime remains in UTC by explicitly specifying the UTC timezone.
  2. Apply the desired format: "yyyy-MM-dd hh:mm:ss tt". 
2024-03-22 09-17-23
Chandra Vikas Sharma

Hi,

below are the description and scope  of Datetimetotext().

UserImage.jpg
Nour Hasan

Tried. Problem is it's converting the date time into local time zone. But I need to show the exactly same date time I received from the server action as UTC format.

2023-01-19 12-23-07
Abhinav Shilwant

Hi @Nour Hasan,

To display both the UTC time and local time correctly in your UI, you can follow these steps:

1. Convert UTC to Local Time:

You can use the DateTimeToText() function combined with ToLocalTime() to convert the UTC time to the user’s local time zone. Here’s an example:

DateTimeToText(ToLocalTime(<your UTC DateTime>), "yyyy-MM-dd hh:mm:ss a")

This will display the date and time in the local time zone with the format YYYY-MM-DD HH:MM:SS AM/PM.

2) Display UTC Time:

For the UTC time, you can simply use DateTimeToText() to format the UTC DateTime value as follows:

DateTimeToText(, "yyyy-MM-dd'T'HH:mm:ss'Z'")

This will give you the desired 2024-09-16T12:08:33Z format.

3) Using Two Expressions:

Since you’re using two expressions, one can display the local time, and the other can display the UTC time as a string. You can use a Text type variable for both.

Hope this helps!

2020-07-21 19-28-50
Rajat Agrawal
Champion
Solution

Hi @Nour Hasan,

As per your issue,

1. What you can do what ever aggregate you are using inside that you should create one calculated attribute and convert your datetime into text data type there itself like below image.

And use calculated attribute to display DateTime.

Hope this helps you!!!


Regards,

Rajat

2024-07-09 06-45-01
Adarsh
Solution

In Outsystems, when you receive a DateTime from a server action, it is typically converted to the local timezone, which is why you're seeing a discrepancy between the UTC time and the original DateTime format.

To solve your problem to display the original DateTime exactly as received (without converting to local timezone):

Since you want to display the exact string as you received it ("2024-09-16T12:08:33Z"), you can store the original DateTime string directly in a Text variable and bind it to your UI expression.

Here’s how you can do it:

  1. In your client action, assign the exact string DateTime value from the server response directly to the Text variable (e.g., ServerDateText = "2024-09-16T12:08:33Z").
  2. Bind this text variable (ServerDateText) to an expression in the UI.

For displaying the UTC time in the required format:

To convert the DateTime to a specific format (e.g., "2024-09-16 12:08:33 PM") while keeping the UTC time, you can:

  1. Use DateTimeToText() function but first ensure the DateTime remains in UTC by explicitly specifying the UTC timezone.
  2. Apply the desired format: "yyyy-MM-dd hh:mm:ss tt". 
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.