String to Timestamp Conversion

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
Madhusudhan
Participant
Posts: 5
Joined: Mon Feb 07, 2011 1:17 am
Location: madhu

String to Timestamp Conversion

Post by Madhusudhan »

How to get below string to timestamp

Input :
05-SEP-13 12.00.00.000000000 AM
01-JAN-99 11.59.59.000000000 PM

Output :
2013-09-05 12:00:00
1999-01-01 23:59:59


Thanks in advance
BI-RMA
Premium Member
Premium Member
Posts: 463
Joined: Sun Nov 01, 2009 3:55 pm
Location: Hamburg

Post by BI-RMA »

Sorry, Madhusan.

Would you like to have your string converted to a timestamp (which is represented internally by some integer-format in most databases) or do you need a different string-output-format for your data?

To save your data as a timestamp have a look at the transformer function StringToTimestamp(). I am not sure if the function supports the precision of your timestamp, but it just might. I haven't got a DataStage installation at hand currently, so I can't try myself.

You can then use the transformer function TimestampToString() to manipulate the output generated from a Timestamp.

Even if you just want to transform the string-representation of the timestamp it may be best to actually transform the string to a timestamp first. This will ensure the input-strings are in correct format.
"It is not the lucky ones are grateful.
There are the grateful those are happy." Francis Bacon
crystal_pup
Participant
Posts: 62
Joined: Thu Feb 08, 2007 6:01 am
Location: Pune

Post by crystal_pup »

Try using Oconv,Iconv functions
BI-RMA
Premium Member
Premium Member
Posts: 463
Joined: Sun Nov 01, 2009 3:55 pm
Location: Hamburg

Post by BI-RMA »

In Enterprise Edition (PX)?
"It is not the lucky ones are grateful.
There are the grateful those are happy." Francis Bacon
crystal_pup
Participant
Posts: 62
Joined: Thu Feb 08, 2007 6:01 am
Location: Pune

Post by crystal_pup »

In case if "User Variable Activity" is used in a sequence then Oconv,Iconv functions can be used
BI-RMA
Premium Member
Premium Member
Posts: 463
Joined: Sun Nov 01, 2009 3:55 pm
Location: Hamburg

Post by BI-RMA »

Of course, but this is only for passing a parameter to a job. Does not look like that to me in the example...
"It is not the lucky ones are grateful.
There are the grateful those are happy." Francis Bacon
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

Unless the OP is on 9.1 as 9.x is not added in the drop down. StringToTimestamp() should do the task.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

They've specified 8.1 in the Additional Info field. A recent discussion of the function and that format is here.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Madhusudhan
Participant
Posts: 5
Joined: Mon Feb 07, 2011 1:17 am
Location: madhu

Post by Madhusudhan »

I achieved it through trimming input time stamp micro seconds.
If year is <50 then added 20 else 19 to the year.

Note : DSLink2.A is input value
stgvar = Left(DSLink2.A,6):'-':(If Right(Left(DSLink2.A,9),2) >=50 Then 19:Right(Left(DSLink2.A,9),2) Else 20:Right(Left(DSLink2.A,9),2)):' ':Right(Left(DSLink2.A,18),8): ' ':Right(DSLink2.A,2)
derivation:

Code: Select all

StringToTimestamp(StageVar,"%dd-%mmm-%yyyy %(H,s).%nn.%ss %(aa,w)")
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

I think there is a environment variable something like cutoff year, if set correctly takes care of adding 19 or 20 in the year.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Open up your Parallel Job Developer's Guide and search for "year_cutoff", it is part of the format mask and will get rid of all those if-then-else shenanigans. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply