I have an application in which every Sunday, it checks a MySQL database for data from the past week. I am trying to find out how to get the date String for each day of the past week. My obvious first attempt was:
Calendar calendar = Calendar.getInstance();
if(calendar.DAY_OF_WEEK == 7){
java.sql.Date date = new java.sql.Date(calendar.getTime().getTime());
String dates[] = new String[7];
for(int i; i < 7; i++){
dates[i] = date.substring(0,7) + date.substring(7, date.length());
}
// Now grab data from the database where the date corresponds with one of these.
}
Today, this would work. However, if it were the 1st through the 6th of a month, this would not work as it wouldn't account for the change in month. Is there a way to get around this. I'm sure somebody has done a similar thing. Thanks.