Determine Number of Days Between Two Dates
There are some situations where you may want to find the number of days between two dates. The simplest method for calculating this number is to use the DAYS FROM expression in a computation script. For example, to find the number of days between Start Date and End Date, you can use the following script:
DAYS FROM( Start Date, End Date )
This computation returns only the basic number of days between two dates, and it does not include the start date in that number. For example, if the start date is January 1, and the end date is January 2, the result of the computation is only one day.
Now let's say you want to find the number of days between two dates, but you want to know only the number of weekdays. In this example, it probably makes more sense to include the beginning date in the total. For example, if you want to calculate the number of weekdays in a given month, you would want to know if the first day of the month is a weekday and include it in the count, if applicable. The following script returns the number of weekdays between Start Date and End Date:
0
SET Date Var TO Start Date
WHILE Date Var <= End Date
IF DAY OF WEEK( Date Var ) > 1 AND DAY OF WEEK( Date Var ) < 7
RESULT + 1
END IF
SET Date Var TO Date Var + 1 DAY
END WHILE In practical situations, you may want to further refine this computation to factor in which days are holidays and exclude them from the count. Once you have the total number of weekdays between two days, you can simply subtract each weekday holiday that falls within those two dates. Here's an example:
IF Start Date <= Holiday AND End Date >= Holiday RESULT - 1 END IF
You would need a separate IF block for each holiday, and a separate computation for each holiday. The computation would need to calculate the date of the holiday, and in the case of holidays that fall on a weekend, the computation would need to determine whether the "observed" holiday is on Monday or Friday. For example, since Easter falls on a Sunday, your computation may return the date of the Monday following Easter. (See Determine Dates for Holidays.)
The following computation determines the number of weekdays between two dates. In addition, it determines if one of three holidays occurs between the two dates and subtracts another day from the total for each holiday found.