Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

time_length

Compute the exact length of a time span


Description

Compute the exact length of a time span

Usage

time_length(x, unit = "second")

## S4 method for signature 'Interval'
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 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()).

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("1980-01-01"), ymd("2014-09-18"))
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("1900-01-01"), ymd("1999-12-31"))
time_length(int, "year")
time_length(as.duration(int), "year")

lubridate

Make Dealing with Dates a Little Easier

v1.7.10
GPL (>= 2)
Authors
Vitalie Spinu [aut, cre], Garrett Grolemund [aut], Hadley Wickham [aut], Ian Lyttle [ctb], Imanuel Costigan [ctb], Jason Law [ctb], Doug Mitarotonda [ctb], Joseph Larmarange [ctb], Jonathan Boiser [ctb], Chel Hee Lee [ctb], Google Inc. [ctb, cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.