如果我有一个给定的日期,我如何找到下个月的第一天和最后一天?
例如,
today <- as.Date("2009-04-04")
我要找
# first date in next month
"2009-05-01"
# last date in next month
"2009-05-31"
最佳答案
你可以用 base R 做到这一点:
today <- as.Date("2009-04-04")
first <- function(x) {
x <- as.POSIXlt(x)
x$mon[] <- x$mon + 1
x$mday[] <- 1
x$isdst[] <- -1L
as.Date(x)
}
first(today)
#[1] "2009-05-01"
first(first(today)) - 1
#[1] "2009-05-31"
关于r - 如何找到下个月的第一天和最后一天?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54362904/