StringToDate conversion problem

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
mac4rfree85
Participant
Posts: 126
Joined: Thu Jul 01, 2010 11:39 pm

StringToDate conversion problem

Post by mac4rfree85 »

Hi Guys,

My Source is SAP which is having a Timestamp value in Char field. So,i am converting the Character field to Date using the below code

Code: Select all

StringToDate(Colname,"%yyyy-%mm%dd")
But i am getting a warning for all the rows and the target is not getting loaded. The warning is

Code: Select all

Conversion error calling conversion routine date_from_ustring data may have been lost
Can somebody guide as where i am doing a mistake.

Cheers!!!!!
Mac4rfree
kbsuryadev
Premium Member
Premium Member
Posts: 46
Joined: Wed Jun 06, 2007 10:32 am

Post by kbsuryadev »

StringToDate(Column,"%yyyy-%mm-%dd")
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Show us what your timestamps look like.
-craig

"You can never have too many knives" -- Logan Nine Fingers
mac4rfree85
Participant
Posts: 126
Joined: Thu Jul 01, 2010 11:39 pm

Post by mac4rfree85 »

@kbsuryadev,, ya correct.. it was a typo.. still showing the same error.
@chulett, my source data is like this 20101007063654
Mac4rfree
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

You have two issues at work here:

1) Your format string does NOT match the format of your timestamp string (I do not see dashes in the source)
2) You're attempting to process a timestamp string with a date function and format.

With StringToDate() and StringToTimestamp(), the format string tells the function what all the various parts of the source string should be. If you have a dash/slash/period/etc. in the format string, it needs to be in your incoming data.

Are you trying to process a timestamp (date+time) or just a date? If the former, use StringToTimestamp() with the proper format string. If the latter, you need to isolate just the date portion of the string to pass to StringToDate()--the Left() function would work well here, or a substring.

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
mac4rfree85
Participant
Posts: 126
Joined: Thu Jul 01, 2010 11:39 pm

Post by mac4rfree85 »

@jwiles, i am trying to process it to a date.
I used the left function to cut out the date alone and then i passed it to the StringToDate also.. Even then, i am getting the same error... :(

Code: Select all

StringToDate(Left(Trim(Colname),8),"%yyyy-%mm-%dd")
Regarding the dashes/slashes, do we really need to have it??? Datastage will not handle it from its side?
Mac4rfree
kbsuryadev
Premium Member
Premium Member
Posts: 46
Joined: Wed Jun 06, 2007 10:32 am

Post by kbsuryadev »

Try this.

StringToDate(Col,"%yyyy%mm%dd").Remove (-) inside the function.

By the way what is your target. Database or File.?
Shruthi
Participant
Posts: 74
Joined: Sun Oct 05, 2008 10:59 pm
Location: Bangalore

Post by Shruthi »

If nothing of that is working, u can also do this

Code: Select all

StringToDate(ColName[1,4]:"-":ColName[5,2]:"-":ColName[7,2])
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

mac4rfree85 wrote:Regarding the dashes/slashes, do we really need to have it??? Datastage will not handle it from its side?
You need to remove them. The mask needs to match what your incoming source field looks like and yours does not have any such delimiter.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Shruthi wrote:If nothing of that is working, u can also do this

Code: Select all

StringToDate(ColName[1,4]:"-":ColName[5,2]:"-":ColName[7,2])
Not sure why U (one of our posters) would do this and a couple of issue here as well. One is that you are missing the format mask that the function needs. The other is that there's really no need to substring your source and introduce a delimiter when all you have to do is provide a proper mask that matches the incoming format.
-craig

"You can never have too many knives" -- Logan Nine Fingers
mac4rfree85
Participant
Posts: 126
Joined: Thu Jul 01, 2010 11:39 pm

Post by mac4rfree85 »

Yes, %yyyy%mm%dd solved the issue... it did not occured to me that it is the input format and not the output format required as i thought...
Thanks for your help guys.. you ppl Rock!!!!!!!!!!!!
Mac4rfree
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

It's an all too common mistake. You need to realize there is no "output format" for a Date field... a date is a date is a date and it is stored in an internal/binary format. Only people readable external representations like in your string need a "format".
-craig

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