[R] Convert number to Date

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Thu Mar 25 22:09:16 CET 2010


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
> Behalf Of Joshua Wiley
> Sent: Thursday, March 25, 2010 1:48 PM
> To: anna
> Cc: r-help at r-project.org
> Subject: Re: [R] Convert number to Date
> 
> Dear Anna,
> 
> Rolf's explanation not withstanding, it has to do with differences in
> how R and Excel treat dates.  If you use
> 
> as.Date(40182, origin="1899-12-30")
> 
> you will get the same date as Excel.  You can look at:
> 
> http://office.microsoft.com/training/training.aspx?AssetID=RC102786151033&CTT=
> 6&Origin=RP102786121033
> 
> For an official guide on how Excel dates are calculated.  Apparently,
> Excel's calendar starts on 1 January 1900.  Why one has to use an
> origin of 30 December 1899 in R...well, I suspect that gets back to
> Rolf's explanation.
> 
> 
> HTH,
> 
> Josh
> 
<<<snip>>>

The reason one must use 1899-12-30, as the origin, is 
1. Excel treats 1900-01-01 as day 1, but as.Date() teats the origin as day 0.
2. According to Wikipedia, Excel copied the Lotus 1-2-3 error of making 1900 a leap year (an extra day)

That accounts for the two day difference.

Hope this is helpful,

Dan 

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA  98504-5204



More information about the R-help mailing list