\HeaderA{format.Date}{Date Conversion Functions to and from Character}{format.Date}
\aliasA{as.character.Date}{format.Date}{as.character.Date}
\aliasA{as.Date}{format.Date}{as.Date}
\methaliasA{as.Date.character}{format.Date}{as.Date.character}
\methaliasA{as.Date.date}{format.Date}{as.Date.date}
\methaliasA{as.Date.dates}{format.Date}{as.Date.dates}
\methaliasA{as.Date.default}{format.Date}{as.Date.default}
\methaliasA{as.Date.factor}{format.Date}{as.Date.factor}
\methaliasA{as.Date.POSIXct}{format.Date}{as.Date.POSIXct}
\methaliasA{as.Date.POSIXlt}{format.Date}{as.Date.POSIXlt}
\keyword{utilities}{format.Date}
\keyword{chron}{format.Date}
\begin{Description}\relax
Functions to convert between character representations and objects of
class \code{"Date"} representing calendar dates.
\end{Description}
\begin{Usage}
\begin{verbatim}
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, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] An object to be converted.
\item[\code{format}] A character string.  The default is
\code{"\%Y-\%m-\%d"}.  For details see \code{\LinkA{strftime}{strftime}}.
\item[\code{...}] Further arguments to be passed from or to other methods,
including \code{format} for \code{as.character} and \code{as.Date}
methods.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The usual vector re-cycling rules are applied to \code{x} and
\code{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 \code{as.Date} methods accept character strings, factors, logical
\code{NA} and objects of classes \code{"\LinkA{POSIXlt}{POSIXlt}"} and
\code{"\LinkA{POSIXct}{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
\code{"date"} (from package \pkg{\LinkA{date}{date}} or
\pkg{\LinkA{survival}{survival}}) and
\code{"dates"} (from package \pkg{\LinkA{chron}{chron}}).

The \code{format} and \code{as.character} methods ignore any
fractional part of the date.
\end{Details}
\begin{Value}
The \code{format} and \code{as.character} methods return a character vector
representing the date.

The \code{as.Date} methods return an object of class \code{"\LinkA{Date}{Date}"}.
\end{Value}
\begin{Note}\relax
The default formats follow the rules of the ISO 8601 international
standard which expresses a day as \code{"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 \code{NA}.  Unfortunately some common implementations
(such as \samp{glibc}) are unreliable and guess at the intended meaning.

Years before 1CE (aka 1AD) will probably not be handled correctly.
\end{Note}
\begin{References}\relax
International Organization for Standardization (1988, 1997, \dots)
\emph{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}
\end{References}
\begin{SeeAlso}\relax
\LinkA{Date}{Date} for details of the date class;
\code{\LinkA{locales}{locales}} to query or set a locale.

Your system's help pages on \code{strftime} and \code{strptime} to
see how to specify their formats.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## 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")
\end{ExampleCode}
\end{Examples}

