Skip to contents

The time between a date and year is calculated using July 1st of the year.

Usage

get_closest_year(x, years = as.character(1800:2400))

Arguments

x

a date vector

years

vector of characters (or numerics) representing years to choose from

Value

a character vector of the closest year in years for each date in x

Examples

get_closest_year(x = as.Date(c("2021-05-15", "2022-09-01")), years = c("2020", "2022"))
#> [1] "2020" "2022"