For Example I have the date range: "1/6/2020 - 7/6/2020" and it have 5 days of Weekdays (1/6 - 5/6) and 2 days of Weekend (6/6 - 7/6). I want to pass it to a function which would return 2 separate date list, weekdays and weekend. How can I do this? I tried the code below, it is working, but i cannot use it outside the "while" function as the return results can only be used in the "while" loop.
SimpleDateFormat dfs= new SimpleDateFormat("yyyy-MM-dd");
Date sd = dformat.parse(param_start);
Date ed = dformat.parse(param_end);
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(sd);
c2.setTime(ed);
String pstart = "";
while(!c1.after(c2)){
System.out.println("WD Date: " + dfs.format(c1.getTime()));
pstart = "'"+dfs.format(c1.getTime())+" 00:00:00',";
out.print(pstart.substring(0,pstart.length()-1));
int dayOfWeek = c1.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == Calendar.FRIDAY) {
c1.add(Calendar.DATE, 3);
} else if (dayOfWeek == Calendar.SATURDAY) {
c1.add(Calendar.DATE, 2);
} else {
c1.add(Calendar.DATE, 1);
}
}
Appreciate any help i could get. Thanks