You need to sign in to do that
Don't have an account?
Adil_SFDC
Get only weekdays in a method
Hi All
I am trying to write a utility method to get only the weekdays. Is there any easy way out. here is my code so far. The return is in the form "09/16/2014 - Tue". I just need the Date.
I am trying to write a utility method to get only the weekdays. Is there any easy way out. here is my code so far. The return is in the form "09/16/2014 - Tue". I just need the Date.
public class Utility_WorkingDays { public List<String> getHeadDates(){ List<String> formattedDates = new List<String>(); List<DateTime> headDates = new List<DateTime>(); DateTime currentDate = DateTime.now(); //Date currentDate = currentDateTime.Date; for (Integer idx=0; idx<28; idx++){ headDates.add(currentDate+idx); } for(DateTime dt: headDates){ String formatDatewithDay = dt.format('MM/dd/yyyy - E'); formattedDates.add(formatDatewithDay); for(Integer i = 0; i< formattedDates.size();i++){ String weekend = formattedDates.get(i); system.debug('here :'+weekend); if(weekend.contains('Sun') || weekend.contains('Sat')){ formattedDates.remove(i); } } } system.debug('dates:'+formattedDates); return formattedDates; } }
All Answers
Save error: Method does not exist or incorrect signature: [String].substring(String)
System.FinalException: Cannot modify a collection while it is being iterated.