+ Start a Discussion
Sridhar Sai GoudSridhar Sai Goud 

I want to calculate no of working days for each month that fall between Start date and End date

Hi Team,

I have 2 custom fields Start Date and End date. I want to show an output where how many working days for each month do have for the given Start Date and End date. My formula gives only the No of total Business days  between Start Date and End Date. 

Ex: If Start Date= 01/20/2016  and End Date= 03/21/2017, it will give me total number of Busines days i.e 305.

However my requirment is to show Jan 2016 = 8,  Feb 2016 = 23, March 2016= 23..so on till End Date month....i.e March 2017= 15 business days. 

It should also consider the Leap year. 
Blake TanonBlake Tanon
I haven't tested this, but something like this would work - it excludes weekends but not holidays.  You'd have to build more in for that logic.
 
public static integer workingDays(date startDate, date endDate){
        integer daysBetween = startDate.daysBetween(endDate);
        integer workingDays = 0;

        for(integer i = 0; i <= daysBetween; i++){
            if(startDate.addDays(i).format('E') != 'Sat' && startDate.addDays(i).format('E') != 'Sun')
                workingDays++
        }
        return workingDays;
    }

 
Sridhar Sai GoudSridhar Sai Goud
But to show working days for each month??
Blake TanonBlake Tanon
pass the first day of the month and last day of the month to that methods.
Shikha AgashiShikha Agashi
Please refer below link for your solutions:

http://help.salesforce.com/HTViewSolution?id=000001100