Void Void - 4 months ago 22
Java Question

How to get the Calendar dates in between?

I want to get the dates in between the calendar, but for some reason this does not work. Any suggestions why? Thanks.

public boolean verifyDate(Calendar cal) {
Calendar toDate = Calendar.getInstance();
toDate.setTime(passToDate);
Calendar fromDate = Calendar.getInstance();
fromDate.setTime(passFromDate);
return !((fromDate.after(cal) && toDate.before(cal)) || DateUtils.isSameDay(fromDate, cal) || DateUtils.isSameDay(toDate, cal));
}

Answer

fromDate.after(cal) - will return true if fromDate will be after the cal, similar thing with before.

If you want to check that cal is between two dates use:

return cal.after(fromDate) && cal.before(toDate) 
    && !(DateUtils.isSameDay(fromDate, cal) || DateUtils.isSameDay(toDate, cal));
Comments