You need to sign in to do that
Don't have an account?
David Tom
Calculate the number of days between two dates while excluding weekends.
I need to count the working days or leave of any employee excluding the weekends,then i need to write code for same.
Refer the below link.
https://help.salesforce.com/HTViewSolution?id=000004526
You can use this below code where salesforce provide the pre built methods of date.
public Decimal findNoOfDays( Date startDate , Date endDate ) {
Decimal NoOfDays = 0;
Date tempStartDate = startDate;
for( integer i = 1; tempStartDate <= endDate; i ++ ) {
if(tempStartDate.daysBetween(tempStartDate.toStartofWeek()) == 0 || tempStartDate.daysBetween(tempStartDate.toStartofWeek()) == -6) {
tempStartDate = tempStartDate.adddays(1); continue; } NoOfDays = NoOfDays+1; tempStartDate = tempStartDate.adddays(1);
}
return NoOfDays ;
}
Thanks,
If it is solve your problem then Mark it as best answer!!
https://success.salesforce.com/answers?id=90630000000gv5PAAQ