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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
rohit1804
Contributor III
Contributor III

How to compare 2 dates

Hi,

I am not able to compare 2 date which is retuning string as output in if else statement in tmap.

I tried below 2 expression but it is not working.

1.  !(Relational.ISNULL(lnk_AllData.UPDT_DTTM)) && lnk_AllData.CREATED_DTTM <= lnk_AllData.END_DTTM && TalendDate.getCurrentDate() >= lnk_AllData.UPDT_DTTM &&
lnk_AllData.UPDT_DTTM > lnk_AllData.END_DTTM ? "a":"b"

 

2 .    ((TalendDate.compareDate(lnk_AllData.CREATED_DTTM,lnk_AllData.END_DTTM,"yyyy-MM-dd HH:mm:ss")==0 || TalendDate.compareDate(lnk_AllData.CREATED_DTTM,lnk_AllData.END_DTTM,"yyyy-MM-dd HH:mm:ss"==-1)) && (TalendDate.compareDate(TalendDate.getCurrentDate(),lnk_AllData.UPDT_DTTM,"yyyy-MM-dd HH:mm:ss")==0 || TalendDate.compareDate(TalendDate.getCurrentDate(),lnk_AllData.UPDT_DTTM,"yyyy-MM-dd HH:mm:ss" ==1)) && (TalendDate.compareDate(lnk_AllData.UPDT_DTTM,lnk_AllData.END_DTTM),"yyyy-MM-dd HH:mm:ss"==1))?"a":"b"

 

 

and all datatype of date columns is date

please help

 

 

Labels (2)
2 Replies
Anonymous
Not applicable

Can you explain what do you want to do with the formula? What are fields and the output required?
Anonymous
Not applicable

Hi,

 

    I considered your first expression as the base logic and I have created the job as shown below. Its working for both conditions.

0683p000009M5Tu.png

 

0683p000009M5U8.png

 

You had specified that your input data is already in date data type. So you do not have to specify date format while doing date comparison. That was the issue in original flow.

0683p000009M5UD.png

 

!(Relational.ISNULL(row2.UPDT_DTTM)) && TalendDate.compareDate(row2.CREATED_DTTM,row2.END_DTTM)<=0 &&
TalendDate.compareDate(TalendDate.getCurrentDate(),row2.UPDT_DTTM)>=0 && TalendDate.compareDate(row2.UPDT_DTTM,row2.END_DTTM)>=0 ? "a":"b" 

Please spare a second to mark the post as resolved if you are happy 🙂

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂