extracting time from date

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
bhaskarjha
Participant
Posts: 67
Joined: Thu Apr 06, 2006 7:13 am

extracting time from date

Post by bhaskarjha »

Hi,
I am trying to extract time part from a column whose data type is Date. For example my sample data is "1/1/1970 10:31:00 PM" and I want to take only "10:31:00 PM". My source table column is Date & target table column is also Date. I have tried it with DSTransform (TIMESTAMP.TO.DATE) but failed.
Thanks,
Bhaskar
Bhaskar Jha
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Just use the substring function, use RIGHT(In.ColumnName,11) since your string looks like it has a variable length date portion.
sb_akarmarkar
Participant
Posts: 232
Joined: Fri Sep 30, 2005 4:52 am
Contact:

Post by sb_akarmarkar »

Hi,

Use substring function in transformer to extract time from Date like
example :substring("1/1/1970 10:31:00 PM",10,11)


Thanks,
Anupam
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

With that particular format, I doubt either portion will be of a fixed length. If that's the case, I'd use the FIELD function to split it at the first whitespace:

Code: Select all

Field(In.ColumnName," ",2,2)
From memory. Otherwise, you could go with Arnd's solution.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Craig - good thought, the function to use is
Field(In.ColumnName," ",2,1)
(although yours will work in this instance because there are no trailing spaces)
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Specifically included the second '2' so that both pieces of the time will be extracted - the actual time and the 'AM/PM' part since it's not in 24 hour format. Assuming, that is, that there is actually a second space in there. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

You are, of course, correct. I'm just so used to European (or military) time that the AM/PM text completed zipped by me :). I think the FIELD function is a better way to go in any case, since it is more robust than using straightforward positional values.
bhaskarjha
Participant
Posts: 67
Joined: Thu Apr 06, 2006 7:13 am

Post by bhaskarjha »

Thanks to all of you for your valuable suggestion. My problem got resolved, I have used one routine to read the source & take only the time part.
Thanks,
Bhaskar
Bhaskar Jha
Post Reply