Suppose I have a Date 20 June 2013
How can I get the Date range for the last week, ie in this case 9 June to 15 June.
Also if the date was 2nd June 2013
You can use JodaTime
for a cleaner solution. With JodaTime
you can do as below:
final DateTime input = new DateTime();
System.out.println(input);
final DateMidnight startOfLastWeek =
new DateMidnight(input.minusWeeks(1).withDayOfWeek(DateTimeConstants.MONDAY));
System.out.println(startOfLastWeek);
final DateMidnight endOfLastWeek = startOfLastWeek.plusDays(6);
System.out.println(endOfLastWeek);