Hi everyone,
I've created a function to calculate the number of workdays between two dates.
I use it to measure how many weekdays have passed since a record in our action log was opened.
Have a look at my new function below.
The only limitation I can see is that any holidays are not taken into account.
What do you think?
- int Diff_Calc(date startDate)
- {
- today = zoho.currentdate;
- totDiff = days360(input.startDate,today);
- diffDiff = (floor((totDiff / 7)) * 2);
- actualDiff = (totDiff - diffDiff);
- startDayofWeek = input.startDate.getDayOfWeek();
- endDayofWeek = today.getDayOfWeek();
- if (startDayofWeek > endDayofWeek)
- {
- Correction = -1;
- }
- else if ((startDayofWeek == 1) && (endDayofWeek == 7))
- {
- Correction = 0;
- }
- else if ((startDayofWeek == 1) || (endDayofWeek == 7))
- {
- Correction = -1;
- }
- else
- {
- Correction = 1;
- }
- correctDiff = (actualDiff + Correction);
- return correctDiff;
- }