How to check if a column is in valid date format

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

sheema
Premium Member
Premium Member
Posts: 204
Joined: Sat Jul 22, 2006 10:20 am

How to check if a column is in valid date format

Post by sheema »

My source is a sequential file,where in i have a column which is of type varchar and length is 8.I need to check whether this column is a date in the format YYYYMMDD.If it is not in that format i need to replace a Null.

Do we have any function to check this.


Thanks
sheema
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Yes, you can search the forum and find custom functions folks have written, or write your own using ICONV and OCONV and ISNULL and other BASIC functions.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Nothing out of the box but its no sweat. Do a substring and check for your limits. I know MM will be greater than 0 and less than 13. Similarly DD will be between 1 and 31, inclusive. You define YYYY. What is a valid date for you. Do a check on that.
If you want to go into more depth, then you can also check if YYYY is a not a leap year and MM is 02 then DD cannot be greater than 28.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Or go the ICONV/OCONV way as Ken suggests :oops:
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
us1aslam1us
Charter Member
Charter Member
Posts: 822
Joined: Sat Sep 17, 2005 5:25 pm
Location: USA

Post by us1aslam1us »

you the len() function and check the length of the field.

Code: Select all

If len(dslink.A)=8 then dslink.A else 'Null'
Oh i am sorry I thought OP just want to check it.
I haven't failed, I've found 10,000 ways that don't work.
Thomas Alva Edison(1847-1931)
sheema
Premium Member
Premium Member
Posts: 204
Joined: Sat Jul 22, 2006 10:20 am

Post by sheema »

How do i use IConv and OCONV to check this and convert into correct format.

Thanks

sheema
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Check this link out.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
sheema
Premium Member
Premium Member
Posts: 204
Joined: Sat Jul 22, 2006 10:20 am

Post by sheema »

Thanks,I am not able to see the premium content.

Any help is appreciated.

Thanks
sheema
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Check again. I made them visible for now. You are 25 posts into your membership. You should really consider becoming a premium member as you get routines written by others and basically solution to your problems in a silver platter.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
sheema
Premium Member
Premium Member
Posts: 204
Joined: Sat Jul 22, 2006 10:20 am

Post by sheema »

No,I cannot see the premium content.


Thanks
sheema
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

How could they? It's all converted Premium Content from the switchover.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sheema
Premium Member
Premium Member
Posts: 204
Joined: Sat Jul 22, 2006 10:20 am

Post by sheema »

I want to do this using Stagevariables.

In first stage variable Stage1 i use IConv(Date,"DYMD[4,2,2]")

Now i want to check the status of the above stage variable and do an OConv().Can you guide me how to do this.


Thanks
sheema
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You can only check the status if you do all that in a Routine, which can then be used to populate your stage variables if you like.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sheema
Premium Member
Premium Member
Posts: 204
Joined: Sat Jul 22, 2006 10:20 am

Post by sheema »

Is there any way that i can validate the date through stage variables.


Thanks
sheema
Post Reply