IsValidDate function not returning 1 or 0

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
adi_2_chaos
Participant
Posts: 96
Joined: Fri Apr 17, 2009 5:58 am
Location: Delhi

IsValidDate function not returning 1 or 0

Post by adi_2_chaos »

Hi All,

I have an input column of Varchar datatype which can have two formats:
ddmmyyyy or yyyymmdd. So to be able to process both types of records, I use the function

Code: Select all

If IsValidDate(StringToDate(StageVar, "%yyyy%mm%dd")) Then StringToDate(StageVar, "%yyyy%mm%dd")
Else
StringToDate(StageVar, "%dd%mm%yyyy")
But while trying to implement the above (for a sample input 04102010), the records get dropped. Upon investigation, I have concluded that this is happening since the function IsValidDate(StringToDate(StageVar, "%yyyy%mm%dd")) is returning NULL (instead of an expected 0), and the record's getting dropped. Also, I get the following warning:
Conversion error calling conversion routine date_from_string data may have been lost
Can anyone please guide me on this

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

Post by pandeesh »

this should definitely throw error: :D

Code: Select all

If IsValidDate(
The first argument for IsValid() is the datatype you are going to validate and the second one is just string representation(so no need to convert to date before validating).
pandeeswaran
HendrikB
Premium Member
Premium Member
Posts: 15
Joined: Tue Feb 07, 2012 6:01 am

Post by HendrikB »

Hi,
apart from a proper function name and syntax, is there (really) no need to validate input data in format "%dd%mm%yyyy" as well?
You could get data like 29022011 or 00102010 which would generate error logs ...
dsusersaj
Premium Member
Premium Member
Posts: 160
Joined: Mon Dec 17, 2007 10:44 am

Post by dsusersaj »

IsValid = Return whether the given string is valid for the given type

I think you need to give data type format as well as you gave. Have you made sure that no NULL value gets into the stage variable?.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

The lesson to take away from this is to first check to see if your string is valid and then convert it only if it is in fact valid. Converting and then checking is too late.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply