getDatesBetween

This code will return a list of date in the long formate, for example: Fri May 16 14:13:38 CDT 2008
public static List getDatesBetween(Date fromDate, Date toDate) { Calendar calendar = Calendar.getInstance(); List dateList = new ArrayList(); if (fromDate.before(toDate)) { Date dateCounter = fromDate; dateList.add(fromDate); while (dateCounter.before(toDate)) { calendar.setTime(dateCounter); int nextDate = calendar.get(Calendar.DATE) + 1; calendar.set(Calendar.DATE, nextDate); dateCounter = calendar.getTime(); dateList.add(dateCounter); } } else if (!fromDate.before(toDate) && !fromDate.after(toDate)) { dateList.add(fromDate); } return dateList; }
Test:
public void test_DatesBetween(){ Date fromDate = DateHelper.incrementDays(new Date(), -4); Date toDate = new Date (); log.warn(DateHelper.getDatesBetween(fromDate, toDate)); }


As an Amazon Associate I earn from qualifying purchases.

My favorite quotations..


“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

"We are but habits and memories we chose to carry along." ~ Uki D. Lucas


Popular Recent Articles