Skip to content

This is a year-month-day method for the calendar_count_between() generic. It counts the number of precision units between start and end (i.e., the number of years or months).


# S3 method for clock_year_month_day
calendar_count_between(start, end, precision, ..., n = 1L)


start, end


A pair of year-month-day vectors. These will be recycled to their common size.



One of:

  • "year"

  • "quarter"

  • "month"


These dots are for future extensions and must be empty.


[positive integer(1)]

A single positive integer specifying a multiple of precision to use.


An integer representing the number of precision units between start and end.


"quarter" is equivalent to "month" precision with n set to n * 3L.


# Compute an individual's age in years
x <- year_month_day(2001, 2, 4)
today <- year_month_day(2021, 11, 30)
calendar_count_between(x, today, "year")
#> [1] 20

# Compute the number of months between two dates, taking
# into account the day of the month and time of day
x <- year_month_day(2000, 4, 2, 5)
y <- year_month_day(2000, 7, c(1, 2, 2), c(3, 4, 6))
calendar_count_between(x, y, "month")
#> [1] 2 2 3