time_length
From lubridate v1.5.6
by Vitalie Spinu
Compute the exact length of a time span.
Compute the exact length of a time span.
Usage
time_length(x, unit = "second")
"time_length"(x, unit = "second")
Arguments
 x
 a duration, period, difftime or interval
 unit
 a character string that specifies with time units to use
Details
When x
is an Intervalclass
object and
unit
are years or months, timespan_length
takes into account
the fact that all months and years don't have the same number of days.
When x
is a Durationclass
, Periodclass
or difftime
object, length in months or years is based on their
most common lengths in seconds (see timespan
).
Value

the length of the interval in the specified unit. A negative number
connotes a negative interval or duration
See Also
Examples
int < interval(ymd("19800101"), ymd("20140918"))
time_length(int, "week")
# Exact age
time_length(int, "year")
# Age at last anniversary
trunc(time_length(int, "year"))
# Example of difference between intervals and durations
int < interval(ymd("19000101"), ymd("19991231"))
time_length(int, "year")
time_length(as.duration(int), "year")
Community examples
Looks like there are no examples yet.