239
Views
13
Comments
Solved
I need to convert the format of date from text to date and time
Question
Application Type
Reactive

Hi i have an one issue i need to convert the date and time values with help of build in function 

the date and time is text  "Fri,07Oct202200:45:27GMT"  i need to convert to this format in the data type as date time month/date/year HH:MM:SS


thanks and regards 

karthick

UserImage.jpg
Puja Rani
Solution

As you mentioned it was returning null value, I tested it. Firstly in the last line you don’t need “/”, corrected it  

TextToDateTime( Substr(Substr(Var1,4,Length(Var1)),0,2)  +"/" +Substr(Substr(Var1,4,Length(Var1)),2,3) +"/" +Substr(Substr(Var1,4,Length(Var1)),5,4)+ " " +Substr(Substr(Var1,4,Length(Var1)),9,8) ) 

Second, noticed a behaviour. If we do conversion all at once in assign, eg Var2 (date time data type) - this returned me null value

  However if I do in two step, eg– Var1(text data type) get the value from below Then in second step do text to date time conversion Var3(date time data type) - this result gave expected outcomeResult - message one is Var2 and in expression highlighted is Var3.  

You can try this and see if you get the value now after conversion.

2023-07-17 04-42-12
Karthick Balaji
Solution

i have used like this Substr(Value.Last_update,2,Length(Value.Last_update))

its right can you help me fix this  issue

2023-01-26 16-03-24
Ana Agostinho

Hello Karthick, 
You can create a function that uses the Substr built-in function and allows to retrieve the date time, assuming the text will always be in the same format. 


After having the day, month, and year separately, you can concat and create the text expression which is allowed to be converted into DateTime by this built-in function: 


Basically, you just need to play around with Built-in functions. :) 

Best regards, 

Ana

2023-07-17 04-42-12
Karthick Balaji
Solution

i have used like this Substr(Value.Last_update,2,Length(Value.Last_update))

its right can you help me fix this  issue

UserImage.jpg
Anjali Choudhary

Hi @Karthick Balaji ,

Also you can use Javascript like this,

Then use FormatDateTime().

Thanks

2023-07-17 04-42-12
Karthick Balaji

inside the server action we cannot able to use the script so only i am like to do it in build in functions

UserImage.jpg
Puja Rani

Hi @Karthick Balaji ,

  • "Fri,07Oct202200:45:27GMT" to get the value of dd mm yyyy hh:mm:ss out of this use below : Substr(Substr(Var1,4,Length(Var1)),0,2)  +" " +Substr(Substr(Var1,4,Length(Var1)),2,3) +" " +Substr(Substr(Var1,4,Length(Var1)),5,4)+ " " +Substr(Substr(Var1,4,Length(Var1)),9,8) 
  • Result of this looks like this -
  • Unfortunately there is no built in function to get month number from name, so refer this post.
  • Once you get the month number, you can arrange in the format which you need. Hope this helps.
2023-07-17 04-42-12
Karthick Balaji

it actual working good even i am also tried that use of substr() but after removing the unwanted thing in the text that date and time after that i am trying to use the data conversion like, main thing is this values comes from API. i am converting the text to date time with some changes.

TextToDateTime(Substr(Substr(Value.Last_update,4,Length(Value.Last_update)),0,2)  +"/"+Substr(Substr(Value.Last_update,4,Length(Value.Last_update)),2,3) +"/"+Substr(Substr(Value.Last_update,4,Length(Value.Last_update)),5,4)+ "/"+Substr(Substr(Value.Last_update,4,Length(Value.Last_update)),9,8))


but i am getting empty values like this

{

    "status": "SUCCESS",

    "message": "AllGood!",

    "data": {

        "ParentCollection": [

            {

                "CollectionId": 50,

                "Device": [

                    {

                        "sn": "100941",

                        "online": 0,

                        "last_update": "1900-01-01 00:00:00"

                    },

                    {

                        "sn": "100945",

                        "online": 0,

                        "last_update": "1900-01-01 00:00:00"

                    },

                    {

                        "sn": "100967",

                        "online": 0,

                        "last_update": "1900-01-01 00:00:00"

                    }

                ]

            },

            {

                "CollectionId": 52,

                "Device": [

                    {

                        "sn": "100989",

                        "online": 0,

                        "last_update": "1900-01-01 00:00:00"

                    },

                    {

                        "sn": "101001",

                        "online": 0,

                        "last_update": "1900-01-01 00:00:00"

                    }

                ]

            }

        ]

    }

}

UserImage.jpg
Puja Rani

TextToDateTime conversion accepts the text in a certain format which is why I mentioned that you need to get the month number from name then arrange in given format then do conversion. 

2023-07-17 04-42-12
Karthick Balaji

okay can you help me for one more thing if i am passing the request some of the parameters are null default outsystems ignore the null values but i need that null values in response how we can achieve this @Puja Rani  i have tried some default values -9 also but incase i need to store the response to entity means it wrong right can you help me for this one.


thanks and regards

karthick

UserImage.jpg
Puja Rani
Solution

As you mentioned it was returning null value, I tested it. Firstly in the last line you don’t need “/”, corrected it  

TextToDateTime( Substr(Substr(Var1,4,Length(Var1)),0,2)  +"/" +Substr(Substr(Var1,4,Length(Var1)),2,3) +"/" +Substr(Substr(Var1,4,Length(Var1)),5,4)+ " " +Substr(Substr(Var1,4,Length(Var1)),9,8) ) 

Second, noticed a behaviour. If we do conversion all at once in assign, eg Var2 (date time data type) - this returned me null value

  However if I do in two step, eg– Var1(text data type) get the value from below Then in second step do text to date time conversion Var3(date time data type) - this result gave expected outcomeResult - message one is Var2 and in expression highlighted is Var3.  

You can try this and see if you get the value now after conversion.

2023-07-17 04-42-12
Karthick Balaji

@Puja Rani  thanks for you reply

i have tried that but still i am not able get that can you see once that my OML file in newcustomiziation 



thanks and regards

karthick after deserialize the device list list append.

SandBox.oml
UserImage.jpg
Puja Rani

Instead of append all , if try do to using for each loop and that two step local variable for data type conversion, if you can check this way.

2023-07-17 04-42-12
Karthick Balaji

i have get that values but instead of - this i need / this for separator 

UserImage.jpg
Puja Rani

ok, good to hear your problem is solved :)

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