53
Views
14
Comments
Solved
Convert text to datetime
Question

Hi ,

I need to convert the following text to date time :

Text - "8/18/2023 5:36:54 PM"

Converted result - 1900-01-01 00:00:00

I used the following function TextToDateTime().

Solution

Hey VR,

Use the below logic to covert that text in your server side code :


NewDateTime(

    TextToInteger(Substr(GivenInput, Index(GivenInput,"/",searchFromEnd:True)+1,4 )) 

   ,  

  TextToInteger(Substr(GivenInput,0 , Index(GivenInput,"/"))) 

   ,

    TextToInteger(Substr(GivenInput, Index(GivenInput,"/")+1,Index(GivenInput,"/",searchFromEnd:True)-Index(GivenInput,"/")-1 ))

    , 

   TextToInteger(Substr(GivenInput, Index(GivenInput," ")+1 ,Index(GivenInput,":")-Index(GivenInput," ")-1 ))+    If(Substr(GivenInput,Index(GivenInput," ",searchFromEnd:True)+1,2)="AM",0,12)

    ,

    TextToInteger(Substr(GivenInput, Index(GivenInput,":")+1 ,Index(GivenInput,":", searchFromEnd:True)-Index(GivenInput,":")-1 ))

    , 

   TextToInteger(Substr(GivenInput, Index(GivenInput,":",searchFromEnd:True)+1 ,Index(GivenInput," ", searchFromEnd:True)-Index(GivenInput,":",searchFromEnd:True)-1 ))

)


Note that here GivenInput ="8/18/2023 5:36:54 PM" 


I am giving this after testing. It will definitely work.

Thanks & Regards,

Sudip Pal

I think that is proper way to convert it on server side and should work fine

Yes Jitendra.I don't see any other idea to solve .

Thanks,

Sudip Pal

Hi Sudip Pal,

It works well. But In my case I need to manipulate many records i.e. more than 10k records need to be manipulated. In your solution we have many functions.

Thank you for your suggestion.

Hey VR,

This is the only option available. I think that you will not face any problem with 10k data. Please try and let me know.

Thanks & Regards,

Sudip Pal

Champion

Hello @Vijay R 

It will return you the default date only because, before conversion, you need to

format the date time in the same way as you are getting the result you can check the format date time function. Also here is the examples that can be convertible to date time


You need to pass the text string in this format

If you dont have the correct format you need to do string manipulation, for that you can use substr() function.

Also I have created a JS based sample that might help you 

https://personal-ejuytnht.outsystemscloud.com/ConvertStringTodate/DateConversion

Thanks

Tousif Khan

ConvertStringTodate.oml

hi Tousif,

Thanks for your solution, but I need to apply this on server side.

Hi Pawan,

Thanks , I have checked this link already ,the solution gives 2 ways :

1-method which is marked as solution will convert only date not datetime.

2-method is regex , this regex converts however could not convert to 24 hour format.

I need to convert the text to datetime as 24hour format.

Hi Vijay R,

To convert the text to date time you have to convert the date of the given string to this format  "2023/18/08  05:36:54" you can use the below JS to convert date format 

JS Code convert Date format 

Input in text/string 

Output in text/string  

var date = $parameters.inpDate;(current format dd/MM/yyyy)

var newdate = date.split("/").reverse().join("-");

$parameters.formatedDate = newdate ;(Convert to yyyy-MM-dd)


AND then you can use textToDatetime function 

Hope this will help you.

Regards


Hi Asiyah,

Thanks for the suggestion, I am looking to apply at the backend server side.

& I hope your suggestion will work for date conversion, anyway looking to convert to date time.

Could you pls share your OML ,so that i can help you with .

Hello VR,

If you share your oml it will be much easier to understand and share proper solution to you.

Or at least share your implementation screenshots.

Please check my OML, i am converting text to datetime format using Javascript.

This might resolve your solution.

sample_test.oml
Solution

Hey VR,

Use the below logic to covert that text in your server side code :


NewDateTime(

    TextToInteger(Substr(GivenInput, Index(GivenInput,"/",searchFromEnd:True)+1,4 )) 

   ,  

  TextToInteger(Substr(GivenInput,0 , Index(GivenInput,"/"))) 

   ,

    TextToInteger(Substr(GivenInput, Index(GivenInput,"/")+1,Index(GivenInput,"/",searchFromEnd:True)-Index(GivenInput,"/")-1 ))

    , 

   TextToInteger(Substr(GivenInput, Index(GivenInput," ")+1 ,Index(GivenInput,":")-Index(GivenInput," ")-1 ))+    If(Substr(GivenInput,Index(GivenInput," ",searchFromEnd:True)+1,2)="AM",0,12)

    ,

    TextToInteger(Substr(GivenInput, Index(GivenInput,":")+1 ,Index(GivenInput,":", searchFromEnd:True)-Index(GivenInput,":")-1 ))

    , 

   TextToInteger(Substr(GivenInput, Index(GivenInput,":",searchFromEnd:True)+1 ,Index(GivenInput," ", searchFromEnd:True)-Index(GivenInput,":",searchFromEnd:True)-1 ))

)


Note that here GivenInput ="8/18/2023 5:36:54 PM" 


I am giving this after testing. It will definitely work.

Thanks & Regards,

Sudip Pal

I think that is proper way to convert it on server side and should work fine

Yes Jitendra.I don't see any other idea to solve .

Thanks,

Sudip Pal

Hi Sudip Pal,

It works well. But In my case I need to manipulate many records i.e. more than 10k records need to be manipulated. In your solution we have many functions.

Thank you for your suggestion.

Hey VR,

This is the only option available. I think that you will not face any problem with 10k data. Please try and let me know.

Thanks & Regards,

Sudip Pal

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