Returns the number of work days between two dates taking into account the provided holiday dates.

CountWorkDays(from, to, holiday = NULL, nonworkdays = c("Sat", "Sun"))

Arguments

from

the initial dates

to

the final dates

holiday

a vector with dates to be excluded.

nonworkdays

a character vector containing the abbreviations of the weekdays (as in day.abb) to be considered non work days. Default is c("Sat","Sun").

Details

The function is vectorised so that multiple initial and final dates can be supplied. The dates are recycled, if their number are different

Value

an integer vector

Author

Andri Signorell <andri@signorell.net>

See also

weekdays, Date Functions

Examples

from <- as.Date("2019-01-01") + rep(0, 10)
to <- as.Date("2020-01-15") + seq(0, 9)

CountWorkDays(from, to)
#>  [1] 272 273 274 274 274 275 276 277 278 279

x <- seq(from[1], from[1]+11, "days")
data.frame(
  date = x, 
  day  = Format(x, fmt="ddd"))
#>          date day
#> 1  2019-01-01 Tue
#> 2  2019-01-02 Wed
#> 3  2019-01-03 Thu
#> 4  2019-01-04 Fri
#> 5  2019-01-05 Sat
#> 6  2019-01-06 Sun
#> 7  2019-01-07 Mon
#> 8  2019-01-08 Tue
#> 9  2019-01-09 Wed
#> 10 2019-01-10 Thu
#> 11 2019-01-11 Fri
#> 12 2019-01-12 Sat

CountWorkDays(from = min(x), to = max(x), holiday = c("2019-01-06", "2019-01-07"))
#> [1] 8