Compute the exact length of a time span
time_length(x, unit = "second") # S4 method for Interval time_length(x, unit = "second")
| x | a duration, period, difftime or interval |
|---|---|
| unit | a character string that specifies with time units to use |
the length of the interval in the specified unit. A negative number connotes a negative interval or duration
When x is an Interval object and
unit are years or months, time_length() takes into account
the fact that all months and years don't have the same number of days.
When x is a Duration, Period
or difftime() object, length in months or years is based on their
most common lengths in seconds (see timespan()).
#> [1] 1811.286# Exact age time_length(int, "year")#> [1] 34.71233#> [1] 34# Example of difference between intervals and durations int <- interval(ymd("1900-01-01"), ymd("1999-12-31")) time_length(int, "year")#> [1] 99.99726#> [1] 99.99452