Bharani Bharani - 8 months ago 37
Java Question

Date Util in java that will explode date range in weeks,month,quarter,year

I am looking for a java library that when given from and to date would return a list of dates in weeks,months,quarter or year which ever is most applicable. I have done this manually and i wanted to know if this is already implemented and tested as a part of a standard package.


Given 1/1/2009 , 1/4/2009 it should give 1/1/2009,1/2/2009,1/3/2009,1/4/2009

Given 1/1/2009 , 1/14/2009 it should give 1/1/2009,1/7/2009,1/14/2009

hope you that is clear :)


The DateTime class provided by Joda Time has methods such as plusDays(int), plusWeeks(int), plusMonths(int) which should help.

Assuming you want to get all the dates between start and end in weeks (pseudocode):

DateTime start = // whatever
DateTime end = // whatever

List<DateTime> datesBetween = new ArrayList<DateTime>();

while (start <= end) {
   DateTime dateBetween = start.plusWeeks(1);
   start = dateBetween;