IF with isdate checking

Four Stars

IF with isdate checking

Hi there,

 

  I am a newbie to talend. I want to ask you, how to do this item below:

 

  •     I want to check the validity of a given date from an input table. If the date is a valid date, then the date will be inserted to output table. if it is not a valid date, then space will be inserted to the column. Both the input and output column are date field and my codes are as below:

     TalendDate.isDate(TalendDate.formatDate("dd-MM-yyyy",row1.birthdate),"dd-MM-yyyy")?row1.birthdate:""

 

    when rebuilding, i got this compilation error: >> Type mismatch: cannot convert from String to Date

    please help me to solve this issue.

 

  • I am also open to ideas on how to make this process easier using Talend.

 

Thank you in advance for helping me.

Sixteen Stars

Re: IF with isdate checking

I suspect that the data type of the row1.birthdate column is String and not Date. The formatDate method requires as Date. All you need to do is this....

 

  TalendDate.isDate(row1.birthdate,"dd-MM-yyyy")?row1.birthdate:""

Of course, your row1.birthdate column will need to hold the date in "dd-MM-yyyy" format. I'd advise adding a tLogRow before the component you are using this logic in, so that you can see what the date format is of your String.

Seven Stars

Re: IF with isdate checking

Hi @azrylln

 

you getting this error due to formatDate function which return string data type  accept only Date type value. So as @rhall_2_0 suggest you can use isDate function directly with your birthdate or if your date is in different pattern use parseDate function.

 

 

Regards
Aashish
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Sixteen Stars

Re: IF with isdate checking


@aashish wrote:

Hi @azrylln

 

you getting this error due to formatDate function which return string data type and isDate function accept only Date type value. So as @rhall_2_0 suggest you can use isDate function directly with your birthdate or if your date is in different pattern use parseDate function.

 

 


This is not true. The isDate method requires two Strings (stringDate and pattern). There is absolutely no point to the isDate method if it accepts a Date object. A Date object is a Date or null.

Seven Stars

Re: IF with isdate checking

yeah @rhali its typo
Regards
Aashish
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.