#' Weekdays
#'
#' Gets the number of weekdays (not Saturday or Sunday) between two dates
#'
#' @param from A date.
#' @param to Another date.
#'
#' @return An integer scalar.
#' @export
#'
#' @examples
#' pts_weekdays()
#' pts_weekdays(as.Date("2000-01-01"), as.Date("1999-12-15"))
#' pts_weekdays(as.Date("2000-01-01"), as.Date("1999-12-15"))
pts_weekdays <- function(from = Sys.Date(), to = dttr::dtt_add_years(from, 1L) - 1) {
check_date(from)
check_date(to)
dates <- dttr::dtt_seq(from, to, units = "days")
weekdays <- !wday(dates, label = TRUE) %in% c("Sat", "Sun")
weekdays <- sum(weekdays)
if(from > to) return(weekdays * -1L)
weekdays
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.