DSXchange: DataStage and IBM Websphere Data Integration Forum
View next topic
View previous topic
Add To Favorites
Author Message
HemaV
Participant



Joined: 09 Jan 2008
Posts: 46
Location: Bangalore
Points: 483

Post Posted: Fri Aug 31, 2012 11:16 pm Reply with quote    Back to top    

DataStage® Release: 7x
Job Type: Parallel
OS: Windows
I've a varchar field with value 8/8/2012 now I want to convert it to 08-08-2012. when i'm trying to convert it to date using string to date function i'm not able to view the data.please provide me the logic to achieve the above..thanks in advance
chulett

Premium Poster


since January 2006

Group memberships:
Premium Members, Inner Circle, Server to Parallel Transition Group

Joined: 12 Nov 2002
Posts: 36792
Location: Denver, CO
Points: 187521

Post Posted: Sat Sep 01, 2012 8:03 am Reply with quote    Back to top    

First we need to note yet again that "08-08-2012" is not a date, it a string - an external representation of a date. So, first question is do you need an actual Date datatype or a String i ...

_________________
-craig

What does it matter to ya, when you got a job to do
you gotta do it well - you gotta give the other fellow hell!
Rate this response:  
Not yet rated
rajnishrajtomar
Participant



Joined: 12 Apr 2012
Posts: 2
Location: India
Points: 29

Post Posted: Sat Sep 01, 2012 3:00 pm Reply with quote    Back to top    

please provide more clarification on your logic.

_________________
Rajnish Singh
Infotrellis India
www.infotrellis.com
Rate this response:  
Not yet rated
HemaV
Participant



Joined: 09 Jan 2008
Posts: 46
Location: Bangalore
Points: 483

Post Posted: Sun Sep 02, 2012 12:27 am Reply with quote    Back to top    

I need a string not a date
Rate this response:  
Not yet rated
ray.wurlod

Premium Poster
Participant

Group memberships:
Premium Members, Inner Circle, Australia Usergroup, Server to Parallel Transition Group

Joined: 23 Oct 2002
Posts: 50158
Location: Canberra, Australia
Points: 272611

Post Posted: Sun Sep 02, 2012 1:34 am Reply with quote    Back to top    

StringToDate() requires a format string that exactly matches the format in which the date is contained within your string. So does DateToString() to get the date into a different format. Even the de ...

_________________
RXP Services Ltd
Melbourne | Canberra | Sydney | Hong Kong
Delivering Outcomes Together
Rate this response:  
Not yet rated
rajnishrajtomar
Participant



Joined: 12 Apr 2012
Posts: 2
Location: India
Points: 29

Post Posted: Sun Sep 02, 2012 6:38 am Reply with quote    Back to top    

Use following function in sequence, it may help you
StringToDate(input.mystring,"%dd/%mm/%yyyy"): it will give you dd-mm-yyyy
DateToString(output.mystring): retun a string in dd-mm-yyyy

otherwise, you can use following logic also:
I feel your date is coming like 8/8/2012,9/12/2012,21/8/2012,21/12/2012 and you need 08-08-2012, 09-12-2012,21-08-2012,21-12-2012 respectively.

Take three stage variables:

svar1: if input.mystring[2,1]='/' Then '0':input.mystring[1,1] Else if input.mystring[3,1]='/'
Then input.mystring[1,2] Else ''

svar2: if input.mystring[4,1]='/' Then '0':input.mystring3,1] Else if ( input.mystring[2,1]='/' and input.mystring[5,1]='/') Then input.mystring[3,2] Else If ( input.mystring[3,1]='/' and input.mystring[5,1]='/') Then '0':input.mystring[4,1] Else If input.mystring[6,1]='/'
Then input.mystring[4,2] Else ''

svar3: if input.mystring[4,1]='/' Then input.mystring[5,4] Else if input.mystring[5,1]='/'
Then input.mystring[6,4] Else if input.mystring[6,1]='/'
Then input.mystring[7,4] Else ''

Output column: svar1:'-': svar2: '-': savr3

_________________
Rajnish Singh
Infotrellis India
www.infotrellis.com
Rate this response:  
Not yet rated
chulett

Premium Poster


since January 2006

Group memberships:
Premium Members, Inner Circle, Server to Parallel Transition Group

Joined: 12 Nov 2002
Posts: 36792
Location: Denver, CO
Points: 187521

Post Posted: Sun Sep 02, 2012 7:00 am Reply with quote    Back to top    

rajnishrajtomar wrote:
Use following function in sequence, it may help you
StringToDate(input.mystring,"%dd/%mm/%yyyy"): it will give you dd-mm-yyyy
DateToString(output.mystring): retun a string in dd-mm-yyyy

Sorry, but the above is incorrect in more ways than one. Please read what Ray posted for the 'why' of that. The rest of the advice is unnecessarily complex, I'd suggest looking into the Field() function as a start to simplify all that.

_________________
-craig

What does it matter to ya, when you got a job to do
you gotta do it well - you gotta give the other fellow hell!


Last edited by chulett on Sun Sep 02, 2012 7:06 am; edited 1 time in total
Rate this response:  
Not yet rated
chulett

Premium Poster


since January 2006

Group memberships:
Premium Members, Inner Circle, Server to Parallel Transition Group

Joined: 12 Nov 2002
Posts: 36792
Location: Denver, CO
Points: 187521

Post Posted: Sun Sep 02, 2012 7:06 am Reply with quote    Back to top    

You'll need a nested pair of conversions to get that string, first StringToDate() and then DateToString(). As Ray noted, you'll need to use the proper format string based on the what the string looks like (or needs to look like) in each function call.

If you are still having problems, post the specific syntax you are using.

I would also suggest checking the Parallel Job Developer's Guide pdf for the Date Formats section, specifically the options listed below Table 6. The first one listed ("s") is a very good one to become familiar with.

_________________
-craig

What does it matter to ya, when you got a job to do
you gotta do it well - you gotta give the other fellow hell!
Rate this response:  
Not yet rated
Display posts from previous:       

Add To Favorites
View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Powered by phpBB © 2001, 2002 phpBB Group
Theme & Graphics by Daz :: Portal by Smartor
All times are GMT - 6 Hours