Date comparison issue - Date.before and Date.after

One Star

Date comparison issue - Date.before and Date.after

Hi,
In a lookup expression I am using the date checking code :-
row4.END_TIME_DT != null && row2.date_2.before(row4.END_TIME_DT)
&& row4.START_TIME_DT != null && row2.date_2.after(row4.START_TIME_DT)
This works great if the row2.date_2 is after row4.START_TIME_DT but not if it is EQUAL to.
All dates are in mm/dd/yyyy hh:mm:ss format.
My issue is how do I test for row2.date_2 'equal to' or 'greater than' row4.START_TIME_DT in the expression??
Thanks on advance,
Highlighted
One Star

Re: Date comparison issue - Date.before and Date.after

Hi,
Thius may not be pretty but it wqorks as a solution :-
row4.END_TIME_DT != null && (row2.date_2.before(row4.END_TIME_DT) || row2.date_2.equals(row4.END_TIME_DT))
&& row4.START_TIME_DT != null && (row2.date_2.after(row4.START_TIME_DT) || row2.date_2.equals(row4.START_TIME_DT))
One Star

Re: Date comparison issue - Date.before and Date.after

You can also use the method compareTo of the Date object.
For instance, if date1 = "01-JAN-2009" and date2 = "02-JAN-2009" then date1.compareTo(date2) will be equal to -1.
If date1 = "02-JAN-2009" and date2 = "02-JAN-2009" then date1.compareTo(date2) will be equal to 0.
If date1 = "03-JAN-2009" and date2 = "02-JAN-2009" then date1.compareTo(date2) will be equal to 1.
Then to get a test if a date is after or equal to another, you can test
if (date1.compareTo(date2) >=0)

Arnaud

Calling Talend Open Studio Users

The first 100 community members completing the Open Studio survey win a $10 gift voucher.

Start the survey

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog