A set of helper functions for dealing with dates in a typical actuarial analysis context.
Derive the number of months elapsed between two dates.
Usage
end_of_month(date)
start_of_month(date)
extract_date(string)
elapsed_months(end_date, start_date)
Value
end_of_month
returns last day of the month given.start_of_month
returns the first day of the month given.extract_date
returns a date object extracted from the provided string.
numeric
Examples
# character input
start_of_month("2020-08-13")
#> [1] "2020-08-01"
end_of_month("2017-10-20")
#> [1] "2017-10-31"
# can handle human-readable dates also
start_of_month("July 7, 1999")
#> [1] "1999-07-01"
end_of_month("February 5, 2019")
#> [1] "2019-02-28"
# date input
start_of_month(as.Date("2020-08-13"))
#> [1] "2020-08-01"
end_of_month(as.Date("2020-10-20"))
#> [1] "2020-10-31"