mcsriram
asked on
Determining date difference excluding weekends:
I want to determine the no. of saturdays & sundays between two dates or any code that can give me the difference between two days excluding weekends would also do.
How can I do this in Lotus Script?
How can I do this in Lotus Script?
Oops, wrong code.
startDate := @Date(start_date_value);
endDate := @Date(end_date_value);
prevSun := @Adjust(startDate; 0; 0; 1-@Weekday(startDate); 0; 0; 0);
nextSat := @Adjust(endDate; 0; 0; 7-@Weekday(endDate); 0; 0; 0);
daysInBetween := (nextSat - prevSun) / 86400+1;
weekEnds := daysInBetween * 2/7;
exclusions := @Weekday(startDate)!=1 + @Weekday(endDate)!=7;
weekEnds - exclusions;
Variations on what I described above... adds all weekend days of the weeks involved (inlcudiig 2 weekend days per partial week, i.e., counts 2 days in start week even if partial week).
Then, drops the "first Sunday" if necessary and ditto the "last Saturday" to account for partial weeks (see exclusions variable).
Thnaks to Don at Chase who first came up with this in 1990, I think.
startDate := @Date(start_date_value);
endDate := @Date(end_date_value);
prevSun := @Adjust(startDate; 0; 0; 1-@Weekday(startDate); 0; 0; 0);
nextSat := @Adjust(endDate; 0; 0; 7-@Weekday(endDate); 0; 0; 0);
daysInBetween := (nextSat - prevSun) / 86400+1;
weekEnds := daysInBetween * 2/7;
exclusions := @Weekday(startDate)!=1 + @Weekday(endDate)!=7;
weekEnds - exclusions;
Variations on what I described above... adds all weekend days of the weeks involved (inlcudiig 2 weekend days per partial week, i.e., counts 2 days in start week even if partial week).
Then, drops the "first Sunday" if necessary and ditto the "last Saturday" to account for partial weeks (see exclusions variable).
Thnaks to Don at Chase who first came up with this in 1990, I think.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Then, add 2 (since you definitely excluded the firt saturday/last sunday). Add another 1 if start=sunday, and another 1 if end=saturday.
startDate := date1;
endDate := date2;
nextSun := @Adjust(startDate; 0; 0; 8-@Weekday(startDate); 0; 0; 0);
prevSat := @Adjust(endDate; 0; 0; -@Weekday(startDate); 0; 0; 0);
easyPart := (@Date(prevSat) - @Date(nextSun)) * 2/7;
easyPart + 2 + (@Weekday(startDate)=1) + (@Weekday(endDate)=7);