Date & Datetime

List of Week end dates in a given range of dates


  1. List<date> weekEndsList = new List<date>();
  2. Date startDate = Date.today().addDays(-12);
  3. Date endDate = Date.today().addDays(53);
  4. System.Debug('Given from date : ' + startDate);
  5. System.Debug('Given to date : ' + endDate);
  6. Date firstWeekEnd = d.toStartofWeek().addDays(6);
  7. Date lastWeekEnd = d1.toStartofWeek().addDays(6);
  8. Integer noOfWeeks = (firstWeekEnd.daysBetween(lastWeekEnd))/7;
  9. for (integer i=0; i<=noOfWeeks; i++)
  10. {
  11.     weekEndsList.add(firstWeekEnd);
  12.     System.Debug('--------: ' + weekEndsList[i]);
  13.     firstWeekEnd = firstWeekEnd.addDays(7);
  14. }

Comments