get_last_week()
and get_last_month()
return the last week or month
interval, respectively, based on a reference date.
Arguments
- date
(optional) A
Date
object with the reference date (default:Sys.Date()
).
Value
An Interval
object with the last week or
month.
See also
Other utility functions:
change_date()
,
extract_seconds()
,
fix_hms()
,
flat_posixt_date()
,
round_time()
Examples
## Scalar example
get_last_week(as.Date("2024-12-06"))
#> [1] 2024-11-24 UTC--2024-11-30 UTC
#> [1] 2024-11-24 UTC--2024-11-30 UTC # Expected
get_last_month(as.Date("2024-12-06"))
#> [1] 2024-11-01 UTC--2024-11-30 UTC
#> [1] 2024-11-01 UTC--2024-11-30 UTC # Expected
## Vector example
get_last_week(as.Date(c("2024-12-06", "2024-12-15")))
#> [1] 2024-11-24 UTC--2024-11-30 UTC 2024-12-08 UTC--2024-12-14 UTC
#> [1] 2024-11-24 UTC--2024-11-30 UTC # Expected
#' [1] 2024-12-08 UTC--2024-12-14 UTC # Expected
get_last_month(as.Date(c("2024-12-06", "2024-11-15")))
#> [1] 2024-11-01 UTC--2024-11-30 UTC 2024-10-01 UTC--2024-10-31 UTC
#> [1] 2024-11-01 UTC--2024-11-30 UTC # Expected
#> [2] 2024-10-01 UTC--2024-10-31 UTC # Expected