Skip to main content
Date & Datetime
List of Week end dates in a given range of dates
- List<date> weekEndsList = new List<date>();
- Date startDate = Date.today().addDays(-12);
- Date endDate = Date.today().addDays(53);
- System.Debug('Given from date : ' + startDate);
- System.Debug('Given to date : ' + endDate);
- Date firstWeekEnd = d.toStartofWeek().addDays(6);
- Date lastWeekEnd = d1.toStartofWeek().addDays(6);
- Integer noOfWeeks = (firstWeekEnd.daysBetween(lastWeekEnd))/7;
- for (integer i=0; i<=noOfWeeks; i++)
- {
- weekEndsList.add(firstWeekEnd);
- System.Debug('--------: ' + weekEndsList[i]);
- firstWeekEnd = firstWeekEnd.addDays(7);
- }
Comments
Post a Comment