Date

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
ntr
Participant
Posts: 110
Joined: Fri Dec 18, 2009 10:30 am
Location: pune

Date

Post by ntr »

Hi,
Iam facing issue from 2 days can any one help on this
My input is
3/21/2001 i want to convert into date fomat
i am using the below function

(StringToDate(Right(Str('0',1):Field(lnk_to_trsf_validation.D_TRADE_DATE,"/",1,1),2):'/':Field(lnk_to_trsf_validation.D_TRADE_DATE,"/",2,2),"%mm-%dd-%yyyy"))
when i am running this i am not able to load into the target.
with warnings and error

Warnings: Data string '0/' does not match format '%mm-%dd-%yyyy': the value for tag %mm has fewer characters than expected.
Conversion error calling conversion routine date_from_ustring data may have been lost.


Please help me on this.

Thanks & regards,
karthikdsexchange
Participant
Posts: 15
Joined: Thu Aug 07, 2008 2:56 am

Re: Date

Post by karthikdsexchange »

StringToDate('03/21/2011',"%mm/%dd/%yyyy") . This will do.
Initially please know the format of your D_TRADE_DATE.
Then it will be easy for conversion.
For that use peek to debug the date format.
Karthik
Make It Work Make It Right Make It Fast
kogads
Premium Member
Premium Member
Posts: 74
Joined: Fri Jun 05, 2009 5:36 pm

Post by kogads »

StringtoDate function expects the second argument as how the input date format is arriving and not how you want the output to look like.
ntr
Participant
Posts: 110
Joined: Fri Dec 18, 2009 10:30 am
Location: pune

Post by ntr »

Hi,

I am getting the format as 3/21/2011.
Today it will be like this for tomarrow it will be 11/21/2011.
So i use the aove function.

The function that is used was right?If not correct me if any wrong.

Thanks & regards,
karthikdsexchange
Participant
Posts: 15
Joined: Thu Aug 07, 2008 2:56 am

Post by karthikdsexchange »

Use stage variable which will do the check on the length of the string.
If length is 10 use same date else 0:date
In the ETL translation, use the function StringToDate.
I recommend this way to make debugging easy for you. Use this as tip.
Karthik
Make It Work Make It Right Make It Fast
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Use %m and %d designators for flexible format.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

ntr,

You posted this same question a few days ago and were answered with what should have been the correct solution (which uses what Ray suggests in his reply). Did you try the suggested solution? Did it work?

Your earlier thread: http://dsxchange.com/viewtopic.php?t=143247

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

James - you don't need any special tags or that 'sid' portion, just the simple URL pasted in works all by itself. FYI. :wink:

Ray - sorry for the (slight) derail but when did the single character date masks become 'flexible format' masks? I thought (back in the day) that %m matches one-digit months and %mm matches two-digit months and never the twain shall meet. Older posts have shenanigans to check lengths and stick a zero on the front of the 'short' months/days. Now they will happily match one or two digits? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

Thanks for the tip, Craig!

I think the variable-width format option came in with v8.0. I don't see it in the docs prior to that (at least not in 7.5.1a).

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If you want a more self-documenting variant, you can use %(m,v)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Thought it was 's' rather than 'v'... or is that yet another variant?
-craig

"You can never have too many knives" -- Logan Nine Fingers
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

V for Vendetta....wait, wrong reference :)

'v' with %ddd (only) to indicate variable-width day of year. "(%ddd,v)"

's' with several of the formats to allow leading spaces. day, month, 2-digit year, and week of year

plus a few scattered ones for formatting day and month strings
- james wiles


All generalizations are false, including this one - Mark Twain.
Post Reply