Posted By

afiedler8 on 03/25/10


Tagged

date days Business weekdays


Versions (?)

Increment a date by a number of business (week) days


 / Published in: R
 

This doesn't take into account holidays.

  1. incrementBusinessDays <- function(x,n) {
  2. x <- as.Date(x)
  3. bWeeks <- floor(n/5)
  4. bDays <- n %% 5
  5. x <- (x + bWeeks*7)
  6. wd <- as.POSIXlt(x)$wday + bDays
  7.  
  8. # Need to wrap around the weekend
  9. if(wd < 1) {
  10. x <- x + bDays - 2
  11. } else if(wd > 5) {
  12. x <- x + bDays +2
  13. } else {
  14. x <- x + bDays
  15. }
  16.  
  17. x
  18. }

Report this snippet  

You need to login to post a comment.