difftime                package:base                R Documentation

_T_i_m_e _I_n_t_e_r_v_a_l_s

_D_e_s_c_r_i_p_t_i_o_n:

     Create, print and round time intervals.

_U_s_a_g_e:

     time1 - time2
     difftime(time1, time2, tz = "",
              units = c("auto", "secs", "mins", "hours", "days", "weeks"))
     as.difftime(tim, format = "%X")

     ## S3 method for class 'difftime':
     round(x, digits = 0)

_A_r_g_u_m_e_n_t_s:

time1, time2: date-time objects.

      tz: a timezone specification to be used for the conversion.
          System-specific, but '""' is the current time zone, and
          '"GMT"' is UTC.

   units: character.  Units in which the results are desired. Can be
          abbreviated.

     tim: character string specifying a time interval.

  format: character specifying the format of 'tim'.

       x: an object inheriting from class '"difftime"'.

  digits: integer.  Number of significant digits to retain.

_D_e_t_a_i_l_s:

     Function 'difftime' takes a difference of two date/time objects
     (of either class) and returns an object of class '"difftime"' with
     an attribute indicating the units.  There is a 'round' method for
     objects of this class, as well as methods for the group-generic
     (see 'Ops') logical and arithmetic operations.

     If 'units = "auto"', a suitable set of units is chosen, the
     largest possible (excluding '"weeks"') in which all the absolute
     differences are greater than one.

     Subtraction of two date-time objects gives an object of this
     class, by calling 'difftime' with 'units="auto"'.  Alternatively,
     'as.difftime()' works on character-coded time intervals.

     Limited arithmetic is available on '"difftime"' objects: they can
     be added or subtracted, and multiplied or divided by a numeric
     vector. In addition, adding or subtracting a numeric vector
     implicitly converts the numeric vector to a '"difftime"' object
     with the same units as the '"difftime"' object.

_S_e_e _A_l_s_o:

     'DateTimeClasses'.

_E_x_a_m_p_l_e_s:

     (z <- Sys.time() - 3600)
     Sys.time() - z                # just over 3600 seconds.

     ## time interval between releases of 1.2.2 and 1.2.3.
     ISOdate(2001, 4, 26) - ISOdate(2001, 2, 26)

     as.difftime(c("0:3:20", "11:23:15"))
     as.difftime(c("3:20", "23:15", "2:"), format= "%H:%M")# 3rd gives NA

