Created
March 9, 2018 10:56
-
-
Save MarkEdmondson1234/a1a8198e658b8f7700f0ec7f2830bdc4 to your computer and use it in GitHub Desktop.
Create month start and end dates for a date range you pass in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_months <- function(date, n){ | |
seq(date, by = paste (n, "months"), length = 2)[2] | |
} | |
make_date_ranges <- function(start, end){ | |
starts <- seq(from = start, | |
to = Sys.Date()-1 , | |
by = "1 month") | |
ends <- c((seq(from = add_months(start, 1), | |
to = end, | |
by = "1 month" ))-1, | |
(Sys.Date()-1)) | |
data.frame(starts,ends) | |
} | |
## useage | |
make_date_ranges(as.Date("2017-01-01"), Sys.Date()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment