diff_days: Difference in days of two dates as a numeric

View source: R/dates.R

diff_daysR Documentation

Difference in days of two dates as a numeric

Description

Finds difftime(date1, date2) (i.e. date1 - date2) using units = "days", then converts to a numeric.

Usage

diff_days(date1, date2, keep_times = FALSE)

Arguments

date1, date2

A date or datetime.

keep_times

Logical. If FALSE any times will be dropped before difference is calculated.

Details

By default, only the date part of any datetime inputs are used (the datetime is first coerced to a date using lubridate::as_date()). If keep_times = TRUE and both date1 and date2 are datetimes then the times will be used. See examples.

Examples

d1 <- lubridate::ymd_hms("2020-02-01 08:00:00")
d2 <- lubridate::ymd_hms("2020-01-01 00:00:00")
d3 <- lubridate::ymd("2020-01-01")
diff_days(d1, d2, keep_times = FALSE)
diff_days(d1, d2, keep_times = TRUE)
diff_days(d1, d3, keep_times = TRUE) # time in d1 not used since d3 is a date


jedwards24/edwards documentation built on Sept. 2, 2023, 8:16 a.m.