Valiadete date field

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
rajkraj
Premium Member
Premium Member
Posts: 98
Joined: Wed Jun 15, 2005 1:41 pm

Valiadete date field

Post by rajkraj »

I have a sequential file,coming in with 10 columns,the 5,6,7,8 and 10 columns are date fields.All the columns 5,6,7,8 have date fields in the format of mm/dd/yyyy.But column 10 has date field coming as

Nov 30 200
Jan 01 175


So,Now i want to validate column 10 saying if date is not coming in as 'mm/dd/yyyy' than set it to Null.Can you explain me,how to do this.


Thanks
kris
Participant
Posts: 160
Joined: Tue Dec 09, 2003 2:45 pm
Location: virginia, usa

Re: Valiadete date field

Post by kris »

Why OCONV function is there for?
~Kris
ratuldey
Participant
Posts: 33
Joined: Fri Jul 13, 2007 4:50 pm

Create and use a Routine

Post by ratuldey »

You can do something like ---
1. Build a Routine say, ValidateDate(Arg1) using Iconv and Status functions (you will get their syntax in the documentation). In the Routine call Iconv with the Argument as the input date and then call Status fucntion.
2. In Transformer where you are loading the Target table column for the date, just use a derivation like -
If (ValidateDate("<inp_date>")<>0) then NULL else <inp_date>.
The Routine would return 0 if the date format is correct and as desired or else would have statuses as 1,2 which signifies there has been a problem in date conversion using Iconv.

Let me know if we were able to build the Routine and use it.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

What is the base year for the last format? You could use ICONV() to get the components, but need to know the offset.

Code: Select all

BadInternalDate = ICONV(In.Column,'D MDY')
Month = OCONV(BadInternalDate,'DM')
Day    = OCONV(BadInternalDate,'DD')
Year   = OCONV(BadInternalDate,'DY') + EraStart
CorrectDate = FMT(Month,"2'0'R"):" ":FMT(Day,"2'0'R"):" ":FMT(Year,"4'0'R")
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Search the forum for a server version of the IsValid() function.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kris
Participant
Posts: 160
Joined: Tue Dec 09, 2003 2:45 pm
Location: virginia, usa

Post by kris »

Searching with few key words will give you answers before you even need to think about posting the question here.

There are several date validation routines (with comments) floating around on this portal.

Here is one from Ray.
~Kris
rajkraj
Premium Member
Premium Member
Posts: 98
Joined: Wed Jun 15, 2005 1:41 pm

Post by rajkraj »

I am sorry,I had tried the below routine before posting this question

FUNCTION IsValidDate(TheDate, Format)
If UnAssigned(Format) Or IsNull(Format) Or UnAssigned(TheDate) Or IsNull(TheDate)
Then
Ans = @NULL
End
Else
Test = Iconv(TheDate, Format)
Ans = Not(Status())
End
RETURN(Ans)

But when i test the routine by passing 2 parameters
i.e Nov 20 200 and the format as "DMDY",it returns a 1 (which means it is a valid format).So my question was the date is a valid date ,but what i intend to test is the format should be mm/dd/yyyy.
Any suggestions on this.
kris
Participant
Posts: 160
Joined: Tue Dec 09, 2003 2:45 pm
Location: virginia, usa

Post by kris »

Iconv(DateString, "D/MDY") would convert the date in both mm/dd/yy and mm/dd/yyyy format into internal format.

So pass the value of "D/MDY" for format when you call below routine. That will do.
Equate RoutineName To 'TestRoutine'
If UnAssigned(Format) Or IsNull(Format) Or UnAssigned(TheDate) Or IsNull(TheDate)
Then
Ans = @NULL
End
Else
Test = Iconv(TheDate, Format)
Ans = Not(Status())
End
RETURN(Ans)
~Kris
rajkraj
Premium Member
Premium Member
Posts: 98
Joined: Wed Jun 15, 2005 1:41 pm

Post by rajkraj »

As Suggested by Kris,i have passed the value 'D/MDY' for the parameter value Format and Date parameter as 'Nov 20 200' ,this gives an output of 1(which means the date is valid).
But my requirement is if the format of the date is other than mm/dd/yyyy than it should say,invalid date(i.e return 0).
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

'D/MDY[2,2,4]' should get you closer.
-craig

"You can never have too many knives" -- Logan Nine Fingers
rajkraj
Premium Member
Premium Member
Posts: 98
Joined: Wed Jun 15, 2005 1:41 pm

Post by rajkraj »

I Even tried D/MDY[2,2,4] in the format parameter.
But even that returns a value 1,When i pass Parameter for the TheDate field as 'Nov 20 200'.
us1aslam1us
Charter Member
Charter Member
Posts: 822
Joined: Sat Sep 17, 2005 5:25 pm
Location: USA

Post by us1aslam1us »

why don't you try the IsValid() routine Ray had suggested in his post.
I haven't failed, I've found 10,000 ways that don't work.
Thomas Alva Edison(1847-1931)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Use the function to determine that the data is valid, and

Code: Select all

InLink.TheString Matches "2N'/'2N'/'4N"
to determine that it matches your required pattern.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
rajkraj
Premium Member
Premium Member
Posts: 98
Joined: Wed Jun 15, 2005 1:41 pm

Post by rajkraj »

Thanks alot Ray,that worked out absolutely perfect.
Post Reply