Noob here! First I am trying to compare dateOne
and dateTwo
with each other, then which ever that has the most recent date (> 0)
take it and compare that versus the cutOffDate
.
If its after cutOffDate
, set that to be FinalDate
, else set cutOffDate
to be FinalDate
. How can I achieve this?
I'm not sure if I'm on the right track here, I am getting the following error with dateOne.compareTo(dateTwo)
:
The method compareTo(String) in the type String is not applicable for the arguments (Date)
public DateServiceImpl process(final DateServiceImpl item) throws Exception {
final Date dateOne = item.getDateOne();
final Date dateTwo = item.getDateTwo();
final BigDecimal amountOne= item.getAmountOne();
final BigDecimal amountTwo= item.getAmountTwo();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
String cutOffDate = "01/01/2020";
Date cDate = sdf.parse(cutOffDate);
if ((amountOne.compareTo(BigDecimal.ZERO) > 0) && (amountTwo.compareTo(BigDecimal.ZERO) > 0)){
if (dateOne.compareTo(dateTwo) <= 0) {
item.setFinalDate(cDate);
}
return null;
}
}