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,
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