[resolved] Date is not supported in the if else condition

One Star

[resolved] Date is not supported in the if else condition

Hi,
I have input excel(row1) with dates in the format "mm/dd/yyyy" and i have mapped the date in tmap expression builder using the if else condition. In the output the the calculated double value should be the result.
Input excel Format:
Date              Condition
08/09/2015          Y
10/09/2015          N
In tmap expression builder, i have given the condition as below,
row1.Condition.equals("Y")? ((TalendDate.diffDate(row1.Date, TalendDate.getCurrentDate(), "dd") < 365 ) ? 0.20 : 0.5):0.0
In the above if condition, the row1.Date is not taking the value from the input excel sheet.
Getting the below error as,
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

Exception in component tMap_1
java.lang.NullPointerException
My requirement is to find the difference between the date from the input excel and current date and if its less than 365 days then reture value 0.20 otherwise 0.5. If the condition not satisfies then should return value 0.
Please help me to correct this one. Or suggest me anyother alternative way to call the date from input excel.

Accepted Solutions
Community Manager

Re: [resolved] Date is not supported in the if else condition

Hi
Read Date column from excel file with Date type, and set its pattern as "MM/dd/yyyy" rather than "mm/dd/yyyy" on the schema. 
Exception in component tMap_1
java.lang.NullPointerException

Please check if there exist null value in Condition column, if so, you need to handle the null value before using the expression like:
row1.Condition.equals("Y")


Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

All Replies
Community Manager

Re: [resolved] Date is not supported in the if else condition

Hi
Read Date column from excel file with Date type, and set its pattern as "MM/dd/yyyy" rather than "mm/dd/yyyy" on the schema. 
Exception in component tMap_1
java.lang.NullPointerException

Please check if there exist null value in Condition column, if so, you need to handle the null value before using the expression like:
row1.Condition.equals("Y")


Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Date is not supported in the if else condition

This works fine. Thank you