# 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.

## Examples

Caution: Some of the computations in this article use the WHILE instruction, which is only available in HotDocs version 6.2 and later.

In the following computations, Date Var is a temporary Date variable used in the WHILE instruction.

Start Date is the starting date.

End Date is the ending date.

Holiday 1 is a computation variable that returns the date of a holiday for the current year.

Holiday 2 is a computation variable that returns the date of a holiday for the current year.

Holiday 3 is a computation variable that returns the date of a holiday for the current year.

### Find the Number of Days Between Two Dates

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.

### Find the Number of Weekdays Between Two Dates

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.)

### Find the Number of Business Days Between Two Dates

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.

Note: This computation assumes that the dates are both in the same year and that the holiday computations return a date for the holiday in the same year. If your dates are not in the same year, you must modify the script accordingly.

```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
IF Start Date <= Holiday 1 AND End Date >= Holiday 1
RESULT - 1
END IF
IF Start Date <= Holiday 2 AND End Date >= Holiday 2
RESULT - 1
END IF
IF Start Date <= Holiday 3 AND End Date >= Holiday 3
RESULT - 1
END IF```