Write your own method which does not take the time into account:
public static int compareDate(Date date1, Date date2) {
if (date1.getYear() == date2.getYear() &&
date1.getMonth() == date2.getMonth() &&
date1.getDate() == date2.getDate()) {
return 0 ;
}
else if (date1.getYear() < date1.getYear() ||
(date1.getYear() == date2.getYear() &&
date1.getMonth() < date2.getMonth()) ||
(date1.getYear() == date2.getYear() &&
date1.getMonth() == date2.getMonth() &&
date1.getDate() < date2.getDate()) {
return -1 ;
}
else {
return 1 ;
}
}
Note that methods getYear()
, getMonth()
and getDate()
have been deprecated. You should go through the Calendar
class and perform the same method.