Calculate Number of Days Between Two Dates
Value
A tibble with a named column containing the calculated number of days.
Examples
date_ex <- dplyr::tibble(
x = seq.Date(
as.Date("2021-01-01"),
by = "month",
length.out = 3),
y = seq.Date(
as.Date("2022-01-01"),
by = "month",
length.out = 3
)
)
age_days(df = date_ex,
start = x,
end = y)
#> # A tibble: 3 × 3
#> x y age
#> <date> <date> <dbl>
#> 1 2021-01-01 2022-01-01 366
#> 2 2021-02-01 2022-02-01 366
#> 3 2021-03-01 2022-03-01 366
date_ex |>
age_days(x, y, "days_between_x_y")
#> # A tibble: 3 × 3
#> x y days_between_x_y
#> <date> <date> <dbl>
#> 1 2021-01-01 2022-01-01 366
#> 2 2021-02-01 2022-02-01 366
#> 3 2021-03-01 2022-03-01 366
date_ex |>
age_days(start = x,
end = lubridate::today(),
colname = "days_since_x")
#> # A tibble: 3 × 3
#> x y days_since_x
#> <date> <date> <dbl>
#> 1 2021-01-01 2022-01-01 1455
#> 2 2021-02-01 2022-02-01 1424
#> 3 2021-03-01 2022-03-01 1396
date_ex |>
age_days(x, y, "days_between_x_y") |>
age_days(x, lubridate::today(), "days_since_x") |>
age_days(y, lubridate::today(), colname = "days_since_y")
#> # A tibble: 3 × 5
#> x y days_between_x_y days_since_x days_since_y
#> <date> <date> <dbl> <dbl> <dbl>
#> 1 2021-01-01 2022-01-01 366 1455 1090
#> 2 2021-02-01 2022-02-01 366 1424 1059
#> 3 2021-03-01 2022-03-01 366 1396 1031