Page 1 of 1

time from string

Posted: Tue Feb 28, 2006 11:25 am
by DSguru2B
Hi guys,
I have the time coming in a string format. eg
12:31:32 is coming in as 123132000. Is there a function or routine in DS which reads in this string and gives me the output 12:31:32.000
Thanks guys.

Posted: Tue Feb 28, 2006 11:31 am
by ArndW
Instead of using the ICONV/OCONV I think your easiest solution is to use

Code: Select all

In.Column[1,2]:':':In.Column[3,2]:':':In.Column[5,2]:'.':In.Column[7.3]

Posted: Tue Feb 28, 2006 11:32 am
by amsh76
You can do it by formating yuor string to the timpstamp format..

Or the alternative and preferred one is to use Iconv/Oconv functions. There are lots of posts for these, please use search feature.

Posted: Tue Feb 28, 2006 11:33 am
by amsh76
You either format your input using substring ...

Or the other alternative and preferred one is to use Iconv/Oconv functions. There are lots of posts for these, please use search feature.

Posted: Tue Feb 28, 2006 11:34 am
by DSguru2B
thanks for the quick reply, but there is a problem with the use of substring.
what if the input is 11320000
this is suppose to be translated to 01:13:20.000
but if i do a substring of the first two places, its going to give me 11
???

Posted: Tue Feb 28, 2006 11:37 am
by DSguru2B
amsh76
the ICONV/OCONV for the MT only works if i have the time in the actual time format. (either one of the few listen in the server manual) my problem is with the way the time is coming in. Its in a string format, the ICONV/OCONV functions spit out a 0 if i feed in a time that coming in the format i specified.
if you have a way to do this, please let me know (i mean using ICONV/OCONV)
thanks

Posted: Tue Feb 28, 2006 11:37 am
by ArndW
Add an IF-THEN-ELSE statement that checks for LEN(In.Column)=8 or explicitly format the column to 9 places padding on the left; i.e. FMT(In.Column,'9"0"R')

Posted: Tue Feb 28, 2006 11:39 am
by DSguru2B
Well, i was hoping i could achieve this by some DS functionality. I already have the logic to manipulate the string using IF/then and substrings. But thats my last option. If nothing else comes to my attention then that would be my course of action.
Thanks Arnd.

Posted: Tue Feb 28, 2006 11:45 am
by amsh76
Dsguru,

You need to have some kind of FMT applied to your input, DS by itself won't know whether to take 01 or 11..unless and until you specify.

Posted: Tue Feb 28, 2006 12:06 pm
by DSguru2B
cool. Thanks guys.

Posted: Tue Feb 28, 2006 12:20 pm
by I_Server_Whale
Hi,

You can also build a custom routine with the statements and method as suggested by ArndW and Amit.

Passing just the input string as Agr1 to the routine as below:

Code: Select all


      FUNCTION StringToTimestamp(Arg1)

Code: Select all


      x = Fmt(Arg1,'9"0"R')

      Ans = x[1,2]:':':x[3,2]:':':x[5,2]:'.':x[7,3]

Code: Select all


      RETURN(Ans)

And now you can use this routine anywhere, anytime you like.

Thanks,
Whale.

Posted: Tue Feb 28, 2006 1:35 pm
by DSguru2B
Thanks naveen. i basically did the exact same thing you mentioned but in the transformer itself. I guess it would be better to put it in a routine.
Thanks once again naveen.

Posted: Tue Feb 28, 2006 1:48 pm
by I_Server_Whale
Yes! It would be the best idea to use a routine for the reason that it can be re-used anywhere and anytime. But if you are like 110% sure that you would never need such functionality again (which I doubt :roll: ), then there is no need to build a routine for a one-time case.

And you are Welcome!

Whale.

Posted: Tue Feb 28, 2006 1:58 pm
by DSguru2B
Actually i already did build a routine. For the very same reason that it is needed more than once in quite a number of different jobs.
Thanks everyone guys.