format.Date               package:base               R Documentation

_D_a_t_e _C_o_n_v_e_r_s_i_o_n _F_u_n_c_t_i_o_n_s _t_o _a_n_d _f_r_o_m _C_h_a_r_a_c_t_e_r

_D_e_s_c_r_i_p_t_i_o_n:

     Functions to convert between character representations and objects
     of class '"Date"' representing calendar dates.

_U_s_a_g_e:

     as.Date(x, ...)
     ## S3 method for class 'character':
     as.Date(x, format = "", ...)

     ## S3 method for class 'Date':
     format(x, ...)

     ## S3 method for class 'Date':
     as.character(x, ...)

_A_r_g_u_m_e_n_t_s:

       x: An object to be converted.

  format: A character string.  The default is '"%Y-%m-%d"'.  For
          details see 'strftime'.

     ...: Further arguments to be passed from or to other methods,
          including 'format' for 'as.character' and 'as.Date' methods.

_D_e_t_a_i_l_s:

     The usual vector re-cycling rules are applied to 'x' and 'format'
     so the answer will be of length that of the longer of the vectors.

     Locale-specific conversions to and from character strings are used
     where appropriate and available.  This affects the names of the
     days and months.

     The 'as.Date' methods accept character strings, factors, logical
     'NA' and objects of classes '"POSIXlt"' and '"POSIXct"'.  (The
     last are converted to days by ignoring the time after midnight in
     the representation of the time in UTC.)  Also objects of class
     '"date"' (from package 'date' or 'survival') and '"dates"' (from
     package 'chron').

     The 'format' and 'as.character' methods ignore any fractional part
     of the date.

_V_a_l_u_e:

     The 'format' and 'as.character' methods return a character vector
     representing the date.

     The 'as.Date' methods return an object of class '"Date"'.

_N_o_t_e:

     The default formats follow the rules of the ISO 8601 international
     standard which expresses a day as '"2001-02-03"'.

     If the date string does not specify the date completely, the
     returned answer may be system-specific.  The most common behaviour
     is to assume that a missing year, month or day is the current one.
      If it specifies a date incorrectly, reliable implementations will
     give an error and the date is reported as 'NA'.  Unfortunately
     some common implementations (such as 'glibc') are unreliable and
     guess at the intended meaning.

     Years before 1CE (aka 1AD) will probably not be handled correctly.

_R_e_f_e_r_e_n_c_e_s:

     International Organization for Standardization (1988, 1997, ...)
     _ISO 8601. Data elements and interchange formats - Information
     interchange - Representation of dates and times._ The 1997 version
     is available on-line at <URL:
     ftp://ftp.qsl.net/pub/g1smd/8601v03.pdf>

_S_e_e _A_l_s_o:

     Date for details of the date class; 'locales' to query or set a
     locale.

     Your system's help pages on 'strftime' and 'strptime' to see how
     to specify their formats.

_E_x_a_m_p_l_e_s:

     ## locale-specific version of the date
     format(Sys.Date(), "%a %b %d")

     ## read in date info in format 'ddmmmyyyy'
     ## This will give NA(s) in some locales; setting the C locale
     ## as in the commented lines will overcome this on most systems.
     ## lct <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")
     x <- c("1jan1960", "2jan1960", "31mar1960", "30jul1960")
     z <- as.Date(x, "%d%b%Y")
     ## Sys.setlocale("LC_TIME", lct)
     z

     ## read in date/time info in format 'm/d/y'
     dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92")
     as.Date(dates, "%m/%d/%y")

