Testing for Date Value

One Star

Testing for Date Value

This should be really simple, however this does appears not to be the case in java
I am trying to filter for "null" date values from SQLServer which appear as '1753-01-01'
eg:
(row1.Initial_Action_Completed_Date=="1753-01-01")?"":
TalendDate.formatDate("dd/MM/yyyy",row1.Initial_Action_Completed_Date)
This fails as follows "Incompatible operand types date and String"
If I try any formats within the test I get errors relating to talend workspace
eg:
(formatDate("yyyy-MM-dd",row1.Initial_Action_Completed_Date)=="1753-01-01")?"":
TalendDate.formatDate("dd/MM/yyyy",row1.Initial_Action_Completed_Date)
I get
"the method is undefined for the type TalendJavaSourceViewer"
So before I just write a nice simple SQL function and curse java is there any reasonable simple solution to this
Seven Stars

Re: Testing for Date Value

The error "Incompatible operand types date and String" is because row1.Initial_Action_Completed_Date is a Date while "1753-01-01" is a String, so they can't be compared. Comparisons need to be made between objects of the same type.
I think the error "the method is undefined for the type TalendJavaSourceViewer" is because you're missing the "TalendDate." part in the condition.
Also, you should not compare objects using == but the .equals or .compareTo methods instead.
So you need either:
row1.Initial_Action_Completed_Date.equals(TalendDate.parseDate("yyyy-MM-dd","1753-01-01"))?"":
TalendDate.formatDate("dd/MM/yyyy",row1.Initial_Action_Completed_Date)
or
TalendDate.formatDate("yyyy-MM-dd",row1.Initial_Action_Completed_Date).equals("1753-01-01")?"":
TalendDate.formatDate("dd/MM/yyyy",row1.Initial_Action_Completed_Date)