I want to show the all week start dates between two dates.
Suppose, I have selected start date as 8th Dec 2015 - 30th Dec 2015, then it should return the results:
6th Dec 2015
13th Dec 2015
20th Dec 2015
27th Dec 2015
If you are using the JodaTime library (or willing to switch to it), which is a personal preference of mine, you can use their dayOfWeek() function to do this. It returns a LocalDate.Property object which you can then manipulate to get the minimum value (effectively being the start of the week).
To get the date you want and return the minimum date for that week, try this:
LocalDate myDate = getSelectedDate();
return myDate.dayOfWeek().withMinimumValue();
To get all dates until the end date, you can loop:
List<LocalDate> weekDates = new ArrayList<>();
LocalDate tmp = getFirstDate().dayOfWeek().withMinimumValue();
// Loop until we surpass end date
while(tmp.isBefore(getEndDate())) {
weekDates.add(tmp);
tmp = tmp.plusWeeks(1);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With