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

srekant
Premium Member
Premium Member
Posts: 85
Joined: Wed Jan 19, 2005 6:52 am
Location: Detroit

Timestamp conversion

Post by srekant »

Hi,

My input is Jan

Code: Select all

12 1995 12:00:00:000AM
and i want the output to be yyyymmdd.How can i achieve this.
Sree
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

This is a string manipulation type operation, no real date mapping is needed. If your input date is in January as you stated and with your InString format as given you could do a In.InString[4,4]:'01':In.InString[1,2] to achieve your request result.
srekant
Premium Member
Premium Member
Posts: 85
Joined: Wed Jan 19, 2005 6:52 am
Location: Detroit

Post by srekant »

ArndW wrote:This is a string manipulation type operation, no real date mapping is needed. If your input date is in January as you stated and with your InString format as given you could do a In.InString[4,4]:'01':In.InString[1,2] to achieve your request result.
but my input date is not going to have month as jan every time
Sree
srekant
Premium Member
Premium Member
Posts: 85
Joined: Wed Jan 19, 2005 6:52 am
Location: Detroit

Post by srekant »

ArndW wrote:This is a string manipulation type operation, no real date mapping is needed. If your input date is in January as you stated and with your InString format as given you could do a In.InString[4,4]:'01':In.InString[1,2] to achieve your request result.
sorry the input is going to be like this

Code: Select all

Jan 12 1995 12:00:00:000AM
Aug 29 1995 12:00:00:000AM
and expecting output to be

19950112
19950707
Sree
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

srekant,

that's nice, so your input format is different from your initial query. Now you need to use a date conversion algorithm instead of a string function. Have you looked at the date conversions that Px offers?
Prashantoncyber
Participant
Posts: 108
Joined: Wed Jul 28, 2004 7:15 am

Post by Prashantoncyber »

Again, I feel it can be done as string manipulation with out using date

conversion like this,

if Field(Instring,1," ")=JAN

then In.InString[4,4]:'01':In.InString[1,2]

else In.InString[4,4]:'07':In.InString[1,2]

Hope not going against ArndW :)

Correct me if i am wrong?

Thanks

Prashant
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Prashant,

looking at your code, you would need to quote 'JAN' and if you only have dates in January and July then you will be set. But what happens with 'MAR'?
Prashantoncyber
Participant
Posts: 108
Joined: Wed Jul 28, 2004 7:15 am

Post by Prashantoncyber »

Arndw,

That's true it will work only for JAN & AUG.
Seeing the sample data provided , i presumed so. :oops:

Thanks
Prashant
lshort
Premium Member
Premium Member
Posts: 139
Joined: Tue Oct 29, 2002 11:40 am
Location: Toronto

Post by lshort »

You could use the code below to determine the month number.
The rest should be a simple matter of concatenation and the StringToDate function.

Put the delimited Month list in the default value for a Stage Variable (svMM). Leave the derivation empty.

svMM(default) = 'Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec'


use this code to get the month number (ie. 01, 02...12) where Month is the string value from your input.

MM =((COUNT(svMM[1,Index(svMM,Month,1)],'|')+1)/100)[3,2]
Lance Short
"infinite diversity in infinite combinations"
***
"The absence of evidence is not evidence of absence."
lshort
Premium Member
Premium Member
Posts: 139
Joined: Tue Oct 29, 2002 11:40 am
Location: Toronto

Post by lshort »

mydate= 'May 12 1995 12:00:00.000 AM'

mydate[8,4]:((COUNT(X[1,Index(X,mydate[1,3],1)],'|')+1)/100)[3,2]:mydate[5,2]

Result = 19950512
Lance Short
"infinite diversity in infinite combinations"
***
"The absence of evidence is not evidence of absence."
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

lshort wrote:You could use the code below to determine the month number.
The rest should be a simple matter of concatenation and the StringToDate function.

Put the delimited Month list in the default value for a Stage Variable (svMM). Leave the derivation empty.

svMM(default) = 'Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec'


use this code to get the month number (ie. 01, 02...12) where Month is the string value from your input.

MM =((COUNT(svMM[1,Index(svMM,Month,1)],'|')+1)/100)[3,2]
Lance,
Check out the lookup_int16_from_string operator in the Modify stage :idea:
Page 27-9 of Parallel Job Developer's Guide for v7.x
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
info_ds
Charter Member
Charter Member
Posts: 88
Joined: Thu Feb 10, 2005 4:36 am
Location: B\'lore

Post by info_ds »

hi lance,

mydate= 'May 12 1995 12:00:00.000 AM'

DateToString(StringToDate(mydate[1,11],"%mmm %dd %yyyy"),"%yyyy%mm%dd")


can we implement this way?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

How about you try it and let US know? Lance is probably asleep as I post.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
info_ds
Charter Member
Charter Member
Posts: 88
Joined: Thu Feb 10, 2005 4:36 am
Location: B\'lore

Post by info_ds »

hi ray,

i tried and got the result --> 19950512

any suggestions?
srekant
Premium Member
Premium Member
Posts: 85
Joined: Wed Jan 19, 2005 6:52 am
Location: Detroit

yeah i also tried out and is working fine thanks guys.

Post by srekant »

info_ds wrote:hi ray,

i tried and got the result --> 19950512

any suggestions?
Sree
Post Reply