time from string

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

time from string

Post 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.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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]
Last edited by ArndW on Tue Feb 28, 2006 11:32 am, edited 1 time in total.
amsh76
Charter Member
Charter Member
Posts: 118
Joined: Wed Mar 10, 2004 10:58 pm

Post 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.
amsh76
Charter Member
Charter Member
Posts: 118
Joined: Wed Mar 10, 2004 10:58 pm

Post 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.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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
???
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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')
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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.
amsh76
Charter Member
Charter Member
Posts: 118
Joined: Wed Mar 10, 2004 10:58 pm

Post 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.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

cool. Thanks guys.
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post 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.
Last edited by I_Server_Whale on Thu Jan 25, 2007 4:38 am, edited 1 time in total.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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.
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post 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.
Last edited by I_Server_Whale on Thu Jan 25, 2007 4:38 am, edited 1 time in total.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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.
Post Reply