IsValid and StringToDate

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
abc123
Premium Member
Premium Member
Posts: 605
Joined: Fri Aug 25, 2006 8:24 am

IsValid and StringToDate

Post by abc123 »

My incoming column has data such as "19950301" and it is char(10). I am trying to do:

StringToDate(IncomingCol, "%yyyy-%mm-%dd") (this by ltself returns all *)

and then I am trying to do:

Isvalid("date",StringToDate(IncomingCol, "%yyyy-%mm-%dd"))

I also tried:

Isvalid(StringToDate(IncomingCol, "%yyyy-%mm-%dd"), "%yyyy-%mm-%dd")
and
Isvalid(IncomingCol, "%yyyy-%mm-%dd")

All have failed. I have an IF condition which displays a value if IsValid of the date returns true and every time the column is empty. I have pretty much tried everything in this forum. Any ideas?
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

Try this.

Code: Select all

IsValid('date',StringToDate(inCol,'%yyyy%mm%dd'))
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

StringToDate(IncomingCol, "%yyyy-%mm-%dd")
As balajisr implies in his example - you cannot include dashes in your date mask when your source data is not, in fact, delimited with dashes as well.

Code: Select all

StringToDate(IncomingCol,"%yyyy%mm%dd")
-craig

"You can never have too many knives" -- Logan Nine Fingers
Zhang Bo
Participant
Posts: 15
Joined: Sun Jul 15, 2007 9:22 pm

Post by Zhang Bo »

according to me,datastage manual has some ambiguity here describing StringToDate:Returns a date from the given string in the given format,in fact,the given format is for the incoming string,so you shouldn't use "%yyyy-%mm-%dd",instead,"%yyyy%mm%dd",of course ,if it's 03011995 in source string,then use "%mm%dd%yyyy"
MaDFroG
abc123
Premium Member
Premium Member
Posts: 605
Joined: Fri Aug 25, 2006 8:24 am

Post by abc123 »

balajisr, your solution worked. However, can you tell me why:

StringToDate(IncomingCol, "%yyyy-%mm-%dd")

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

Post by ArndW »

This is your output representation for an invalid date format.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The date format string must match the date format.
"%yyyy-%mm-%dd" matches "1995-03-01" but does not match "19950301".
"%yyyy%mm%dd" matches "19950301" but does not match "1995-03-01".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

As Arnd and Ray mentioned your date in string format does not match your format string in StringToDate().
devidotcom
Participant
Posts: 247
Joined: Thu Apr 27, 2006 6:38 am
Location: Hyderabad

Post by devidotcom »

Nice post helped me resolve my issue
Post Reply