Date validation

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
vskr72
Premium Member
Premium Member
Posts: 128
Joined: Wed Apr 28, 2004 9:36 pm

Date validation

Post by vskr72 »

I have a date column that has a value like 11/30/20011. THis is a an invalid date format. SO, I was trying to use this below condition in transformer and Iw as expecting the value to be NULL.But it turns out that it is giving a value like 11/30/2001. Looks like it is takign the first 4 characters of the year. I think I am missing something here. Can you pls help?

Code: Select all

If IsValid('date', StringToDate(ToTfm.AS_OF_DATE,"%mm/%dd/%yyyy")) then StringTODate(ToTfm.AS_OF_DATE,"%(m,s)/%(d,s)/%yyyy") else SetNull() 
Kirtikumar
Participant
Posts: 437
Joined: Fri Oct 15, 2004 6:13 am
Location: Pune, India

Post by Kirtikumar »

I think you would have to use Len function in addition to normal validate function. We had same issue and we ended up adding len function as well.
Regards,
S. Kirtikumar.
Mike
Premium Member
Premium Member
Posts: 1021
Joined: Sun Mar 03, 2002 6:01 pm
Location: Tampa, FL

Post by Mike »

The second argument to the IsValid function should be your unconverted input string. Since you have converted it to a date and specified a format string, you have explicitly converted the string to a date using the first four digits of the year, which then, of course, passes the IsValid function.

Mike
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

The below will cover your requirement

Code: Select all

if len(Field(ToTfm.AS_OF_DATE,'/',3))<>4 then SetNull() else (If IsValid('date', StringToDate(ToTfm.AS_OF_DATE,"%mm/%dd/%yyyy")) then StringTODate(ToTfm.AS_OF_DATE,"%(m,s)/%(d,s)/%yyyy") else SetNull())
pandeeswaran
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Re-read Mike's post.

Validate then convert only if valid.
Last edited by chulett on Fri Dec 16, 2011 8:02 am, edited 1 time in total.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Mike
Premium Member
Premium Member
Posts: 1021
Joined: Sun Mar 03, 2002 6:01 pm
Location: Tampa, FL

Post by Mike »

Note the difference between these:

Code: Select all

IsValid("date", "11/30/20011", "%mm/%dd/%yyyy")
and

Code: Select all

IsValid("date",StringToDate("11/30/20011", "%mm/%dd/%yyyy"))
Mike
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

Good catch!!
pandeeswaran
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

I think this is the time to resolve this topic!!
pandeeswaran
vskr72
Premium Member
Premium Member
Posts: 128
Joined: Wed Apr 28, 2004 9:36 pm

Post by vskr72 »

Thank you everyone for your valuable inputs. I will try it out.
vskr72
Premium Member
Premium Member
Posts: 128
Joined: Wed Apr 28, 2004 9:36 pm

Post by vskr72 »

Thank you everyone for your valuable inputs. I will try it out.
Post Reply