Counts the number of complete calendar units (years, months, or days) between two date-time values, rounding down to the nearest whole unit.

count_calendar_units(x, y, unit = c("years", "months", "days"), floor = TRUE)

Arguments

x

A date-time representing the start of the interval.

y

A date-time representing the end of the interval.

unit

A character string specifying the calendar unit to count. One of "years", "months", or "days".

floor

floor A logical scalar. If TRUE (default), the result is rounded down to the nearest whole integer.

Value

An integer giving the number of complete calendar units between x and y.

Examples

if (FALSE) { # \dontrun{
x <- lubridate::ymd("2020-01-01")
y <- lubridate::ymd("2023-06-01")

count_calendar_units(x, y, "years")
count_calendar_units(x, y, "months")
count_calendar_units(x, y, "days")
} # }