I want a list of dates between start date and end date.
The result should be a list of all dates including the start and end date.
Something like this should definitely work:
private List getListOfDaysBetweenTwoDates(Date startDate, Date endDate) {
List result = new ArrayList();
Calendar start = Calendar.getInstance();
start.setTime(startDate);
Calendar end = Calendar.getInstance();
end.setTime(endDate);
end.add(Calendar.DAY_OF_YEAR, 1); //Add 1 day to endDate to make sure endDate is included into the final list
while (start.before(end)) {
result.add(start.getTime());
start.add(Calendar.DAY_OF_YEAR, 1);
}
return result;
}