226
Views
8
Comments
Solved
Text to DateTime conversion

I'm trying to convert Text (String) to DateTime From an API But it throws me an error.I tried TextToDateTime() but it doesn't help 

"OS-BERT-60600 - Error executing GetAllAttributes Failed to deserialize JSON to Response: Failed to parse response of the method 'GetAllAttributes' of the 'Analytics' REST API: Parsing 'attributes.Updated_Timestamp ': Could not convert string to DateTime: 24.3.2023 00:00:00. Path 'attributes.Updated_Timestamp ', line 1, position 1747. "

2022-07-12 01-10-14
Jithu Cheriath Thomas
Solution

Hi Joe, 

I think youre trying to convert a string to Timestamp directly from the api call by setting field type to DateTime or Timestamp . You cannot convert directly from the output of an api call before serialising into a structure, after the serialising add the logic to convert the text to date time.

I hope this helps..


Thanks !!!!!!

2022-01-24 13-22-23
Vaibhav Patidar

Hi Joe,

Please check the below forum discussion which is similar to your issue.

https://www.outsystems.com/forums/discussion/81626/text-to-date-with-different-format/

Thanks

2024-03-22 09-17-23
Chandra Vikas Sharma

Hi Joe,

It is  generally happens when the Response is not a valid JSON .This can happen for many number of reasons, so it's possible to happen even if most of the time the server still returns a valid response.

can you please check  response and mapping to the structure you have created specially all the data types of the response and structure should match. 

Thanks

CV


2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Joe,

A "failed to deserialize JSON" means that the JSON you received from the API has a different format from the Structures you've defined to deserialize it to.

I'm really not sure what kind of "TextToDateTime" you have "tried", because the error is in the automatic deserialization of JSON, before any of your own code runs. Are you sure you understand how API calls in OutSystems work?

In this case, the error message says it all: "Could not convert string to DateTime: 24.3.2023 00:00:00". This makes sense, because "24.3.2023" is not a valid date format for OutSystems, which only accepts yyyy-MM-dd-type formats (so "2023-03-24"), and if combined with a time, needs a "T" between the date and time, and a "Z" for UTC time.

So the best course of action for you is to change the Date Time Attribute of the Structure to a Text, and convert that to a valid date/time value by extracting the day, month and year, and use the "NewDate()" built-in Function.

2023-07-20 11-15-41
Joe AJ

The Attribute of the structure is "Text"only.Im mapping this response from api to OS table.but in that OS table,the attribute should be DateTime.That's why i convert Text To DateTime

UserImage.jpg
Nani

The Date format is not correct for TextToDateTime Conversation where "24.3.2023" is inCorrect, "2023.3.23" is correct format.

First, Change the Date format text from the api and after try to convert the TextToDateTime function.

2025-04-08 13-09-23
Shubham Shrivastava

Hi Joe,

It's giving an error because TextToDateTime converts the text to DateTime by reading the value in the 1900-01-01 00:00:00 format, but the response from the API is in another format, i.e., 24.3.2023 00:00:00.

You can change the format of your text using the substr function and then convert it to DateTime.

i.e.

TextToDate(Substr(DateText, 6, 4) + "-" + Substr(DateText, 3, 2) + "-" + Substr(DateText, 0, 2))

2022-07-12 01-10-14
Jithu Cheriath Thomas
Solution

Hi Joe, 

I think youre trying to convert a string to Timestamp directly from the api call by setting field type to DateTime or Timestamp . You cannot convert directly from the output of an api call before serialising into a structure, after the serialising add the logic to convert the text to date time.

I hope this helps..


Thanks !!!!!!

2024-05-22 10-21-41
Mohammad Hasib

As per the error detail the format is wrong of your string which is received through API.

TextToDateTime function accepts the string in the below format.  

TextToDateTime("2002.01.01 01:01:01") = #2002-01-01 01:01:01# 

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