[R] strftime - Dates from Excel files

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Feb 3 15:00:25 CET 2012


On Fri, 3 Feb 2012, Ana wrote:

> Hi
>
> I have many excel files were the Date field was not declared as date,
> so the dates look like this: 1/2/1978
> I know that the format is day/month/year
>
> How can I make R change this to Date format?
>
> If I use strftime, I get wrong dates:

So use as.Date to convert to the Date class.

> as.Date(dataset,"%d/%m/%Y")
[1] "1978-02-01"

>
> dataset=c("1/2/1978")
>
> strftime(dataset,"%d/%m/%Y")
> "19/02/0001"

On some unstated OS (how year 1 is represented is OS-dependent). 
The format in strftime applies to output: the default one is used for 
input.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list