The below code will find the number of business days between two days. Change the below code according to your requirement.
By default, I have assigned Saturday and Sunday as default weekend. Change this code according to your requirement.
By default, I have assigned Saturday and Sunday as default weekend. Change this code according to your requirement.
- public class BusinessDayCalculation
- {
- public static Integer calculateWorkingDays(Date startDate, Date endDate)
- {
- Set<Date> holidaysSet = new Set<Date>();
- for(Holiday currHoliday : [Select ActivityDate from holiday])
- {
- holidaysSet.add(currHoliday.ActivityDate);
- }
- Integer workingDays = 0;
- for(integer i=0; i <= startDate.daysBetween(endDate); i++)
- {
- Date dt = startDate + i;
- DateTime currDate = DateTime.newInstance(dt.year(), dt.month(), dt.day());
- String todayDay = currDate.format('EEEE');
- if(todayDay != 'Saturday' && todayDay !='Sunday' && (!holidaysSet.contains(dt)))
- {
- workingDays = workingDays + 1;
- }
- }
- System.debug('--Working days'+workingDays);
- return workingDays;
- }
- }
how to apply this class into salesforce object??
ReplyDeleteCan you write a logic for count half day am and half day pm checkbox value in this code ???
ReplyDelete