-4

I want to calculate number of days between two dates by excluding the weekends. enter image description here

  • Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Aug 29 '18 at 10:51
  • 2
    Possible duplicate of [Calculate the number of weekdays between 2 dates in R](https://stackoverflow.com/questions/5046708/calculate-the-number-of-weekdays-between-2-dates-in-r) – phiver Aug 29 '18 at 11:27

2 Answers2

1

You can make a sequence of dates (and days, both with lubrirdate), filter out the weekends and count the number of rows:

library(dplyr)
library(lubridate)

df <- data_frame(date = seq(ymd("2018-06-01"), ymd("2018-09-30"), by = "days"))

days <- mutate(df, day = wday(date, label = T)) %>%
  filter(day != "Sat", day != "Sun") %>%
  nrow()
Paul
  • 2,877
  • 1
  • 12
  • 28
0

You can do it with help of library chron Sample Code:

library(chron)
number_of_days <- (START_DATE,END_DATE,by=1)

length(number_of_days)
length(number_of_days[!is.weekend(number_of_days)])

Hope this helps

Hunaidkhan
  • 1,411
  • 2
  • 11
  • 21