as.duration

0th

Percentile

Change an object to a duration (difftime).

Change an object to a duration (difftime).

Keywords
manip, classes, methods, chron
Usage
as.duration(x)
Arguments
x
an interval, period, or numeric object
Details

as.duration changes interval, period and numeric objects to duration objects, which are difftime objects. Numeric objects are changed to duration objects with the seconds unit equal to the numeric value.

Durations are exact time measurements, but periods are relative time measurements. See periods. The length of a period depends on when it occurs. Hence, a one to one mapping does not exist between durations and periods. When used with a period object, as.duration provides an inexact estimate of the length of the period; each time unit is assigned its most common number of seconds. Periods with a months unit cannot be coerced to durations because of the variability of month lengths. For an exact transformation, first transform the period to an interval with as.interval.

Value

  • a duration object

See Also

duration, new_duration

Aliases
  • as.duration
  • as.duration.default
  • as.duration.period
  • as.duration.interval
  • as.duration.difftime
Examples
span <- new_interval(as.POSIXct("2009-01-01"), as.POSIXct("2009-08-01")) #interval
# 211.9583 days beginning at 2009-01-01
as.duration(span)
# Time difference of 211.9583 days
as.duration(10) # numeric
# Time difference of 10 secs}
Documentation reproduced from package lubridate, version 0.1, License: GPL

Community examples

ankitkatiyar91 at Aug 15, 2017 lubridate v1.6.0

# Get the hours between two dates as.duration(interval("2015-01-20 09:50:34", "2015-01-20 16:37:07")) #Output "24393s (~6.78 hours)" # Get the numeric value of it as.double(as.duration(interval("2015-01-20 09:50:34", "2015-01-20 16:37:07"))) #Output 24393