dtt_diff {dttr2}R Documentation

Time Difference

Description

Gets the time difference in secs, minutes, hours, days or weeks. Uses difftime() but floors x and y first after coercing to POSIXct and adjusts the timezone of y to match that of x.

Usage

dtt_diff(x, y, units = "secs", as_difftime = FALSE)

Arguments

x

An object that can be coerced to a POSIXct using dtt_date_time().

y

An object that can be coerced to a POSIXct using dtt_date_time().

units

A string of the time units. The possible values are "secs", "minutes", "hours", "days" or "weeks".

as_difftime

A flag specifying whether to return a difftime vector.

Value

A numeric vector of the time difference.

Examples

dtt_diff(
  as.Date(c("2001-01-02", "2000-12-31")),
  as.Date("2001-01-01"),
  "hours"
)
dtt_diff(as.Date("2001-01-02"), as.Date("2001-01-01"), "weeks")

[Package dttr2 version 0.5.0 Index]