Date 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
ravikumarreddy
Participant
Posts: 9
Joined: Tue Apr 05, 2005 4:39 am

Date Conversion

Post by ravikumarreddy »

Hai All,

I have a date field of the format 1/1/2005 and my output should look like 2005-01-01. How can i achieve this. Thanx in Advance

Regard's
RAVI
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Take a look in the Documentation and also in this forum at the StringToDate and DateToString functions.
ravikumarreddy
Participant
Posts: 9
Joined: Tue Apr 05, 2005 4:39 am

Post by ravikumarreddy »

Hai ArndW,

i have tried using StringToDate(ip.date,"%yyyy-%mm-%dd")
iam getting the output as

"**********",2005,1,1,1,7,1,1,1,31,"SATURDAY","JANUARY

Regard's
RAvi
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

The output shows that the conversion wasn't successful, either because of a bad format or a bad input type date. If you are getting a Date type field from a database, you would first need to DateToString and then a StringToDate with the new format.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

StringToDate(ip.date,"%yyyy-%mm-%dd") specifies that the input string is in YYYY-MM-DD format. This is not how you originally represented the problem.
What you probably need is something of the form

Code: Select all

DateToString(StringToDate(ip.date,"%mm/%dd/%yy"), "%yyyy-%mm-%dd")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ravikumarreddy
Participant
Posts: 9
Joined: Tue Apr 05, 2005 4:39 am

Post by ravikumarreddy »

Hai Ray,

StringToDate function is working if my input date is 01/01/2005(having length 10). It is not working if the input data is 1/1/2005(having the length 8).Why is it so. Thanx in Advance

Regards
Ravi
ravikumarreddy
Participant
Posts: 9
Joined: Tue Apr 05, 2005 4:39 am

Post by ravikumarreddy »

hai Ray,

I have got the output in this way

StageVariable1
if Len (Field(DSLink2.date_f,"/",1))=1 then "0":Field(DSLink2.date_f,"/",1) else Field(DSLink2.date_f,"/",1)
StageVariable2
if Len (Field(DSLink2.date_f,"/",2))=1 then "0":Field(DSLink2.date_f,"/",2) else Field(DSLink2.date_f,"/",2)

Concatenating both
StringToDate(Right(DSLink2.date_f,4):StageVar1:StageVar,"%yyyy%mm%dd")

I have got the result by doing this.

But i need to do it in simpler way. Any suggestions

Regard's
Ravi
lshort
Premium Member
Premium Member
Posts: 139
Joined: Tue Oct 29, 2002 11:40 am
Location: Toronto

Post by lshort »

This works...a little simpler...maybe

svDay
((Field(DSLink3.f1,'/',1))/100)[3,2]
svMonth
((Field(DSLink3.f1,'/',2))/100)[3,2]
svYear
Field(DSLink3.f1,'/',3)


StringToDate(svMonth:'/':svDay:'/':svYear,"%mm/%dd/%yyyy")
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 »

btw: You could also do it all in the derivation without the StageVariables

StringToDate(((Field(DSLink3.f1,'/',2))/100)[3,2]:'/':((Field(DSLink3.f1,'/',1))/100)[3,2]:'/':Field(DSLink3.f1,'/',3),"%mm/%dd/%yyyy")
Lance Short
"infinite diversity in infinite combinations"
***
"The absence of evidence is not evidence of absence."
Post Reply