Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
REjaz1662272866
Contributor
Contributor

IF/ELSE condition in Talend

Hey!

Can someone please how to conduct an else if function while comparing 2 variables? Eg: 'If beginningdate < endingdate, write T or else write F.

Please note, I don't want to compare a any variable with an integer, but I want to compare actual two variables present in my schema.

Labels (4)
1 Solution

Accepted Solutions
Anonymous
Not applicable

the operator < does not work with string type, you need to convert string data to Date,

TalendDate.parseDate("yyyy-MM-dd",row1.​beginningdate).getTime()<TalendDate.parseDate("yyyy-MM-dd", row1.endingdate).getTime()?"T":"F"

 

//"yyyy-MM-dd" is the date pattern, change it based on your real date format.

View solution in original post

5 Replies
Anonymous
Not applicable

if the data type is Date, then you can write the expression like this:

row1.beginningdate.getTime()<row1.endingdate.getTime()?"T":"F"

 

 

REjaz1662272866
Contributor
Contributor
Author

The data type is string in my case.

Anonymous
Not applicable

the operator < does not work with string type, you need to convert string data to Date,

TalendDate.parseDate("yyyy-MM-dd",row1.​beginningdate).getTime()<TalendDate.parseDate("yyyy-MM-dd", row1.endingdate).getTime()?"T":"F"

 

//"yyyy-MM-dd" is the date pattern, change it based on your real date format.

REjaz1662272866
Contributor
Contributor
Author

Worked great. Thankyou!

ThWabi
Creator II
Creator II

Hello REjaz1662272866,

 

a solution (without .getTime()) might be:

 

TalendDate.compareDate(TalendDate.parseDate("yyyy-MM-dd", row1.beginningDate), TalendDate.parseDate("yyyy-MM-dd", row1.endingDate)) < 0 ? "T" : "F"

 

Best regards,

 

Thomas