[R] Serial Date

David Winsemius dwinsemius at comcast.net
Mon Mar 14 17:00:29 CET 2011


On Mar 14, 2011, at 6:36 AM, Allan Engelhardt wrote:

>
>
> On 14/03/11 02:00, Raoni Rosa Rodrigues wrote:
>> Hello R Help,
>>
>> I'm working in a project with a software that register date and  
>> time data in serial time format. This format is used by excel, for  
>> exemple. In this format, 40597.3911423958 is 2011/2/23 09:23:15.
>
> Not on my system,

Because ... There is a reasonably well understood MS bug in how it  
handles the non-existent 1900-02-29. (It _still_ accepts that as a  
valid date and calls it 60. I just re-demonstrated this amazingly  
persistent bug behavior on the Mac Excel 2011 variant.  )

http://finzi.psych.upenn.edu/R/library/cxxPack/html/serialNumber.html
http://finzi.psych.upenn.edu/R/Rhelp02/archive/22942.html

(I don't think Gabor's speculation regarding the migration from  
Windows Excel to Mac Excel is possibly correct since Excel was  
introduced on the Mac years before Windows was even a crash-prone GUI  
on top of MS-DOS. The claim on one MS page is that the bug originated  
in Lotus 1-2-3 and was emulated by Multiplan for compatibility. )

-- 
David.



> but this should get you going:
>
> ( a<- as.POSIXct("2011-02-23 09:23:15.00001", tz="GMT") )
> # [1] "2011-02-23 09:23:15 GMT"
> ( b<- difftime(a, ISOdatetime(1900,1,1,0,0,0), tz="GMT",  
> units="days") )
> # Time difference of 40595.39 days
> as.double(b)
> # [1] 40595.39
> options("digits.secs" = 6)
> ISOdatetime(1900, 1, 1, 0, 0, 0) + 40597.3911423958*60*60*24 # TZ  
> dependent
>> [1] "2011-02-25 09:23:14.702997 GMT"
>
>
>
> Hope this helps a little.
>
> Allan
>
>>  First part is number os days since 1900/1/1, and second part is a  
>> fraction of a day.
>>
>> I need to make this transformation in R, and use it to make some  
>> algebrian operations. I found that function 'serialNumber' of  
>> package 'cxxPack' transform a as.data class object in this format,  
>> but without time fraction. But I can't find nothing to do the  
>> inverse way, transform serial date format in a POSIX class, for  
>> exemple.
>>
>> Since now, thanks for your time and atention.
>>
>> All best,
>>
>> Raoni
>> Associate Researcher
>> Fish Passage Center
>> UFMG, Brazil.
>>
>>
>> "Fica proibido o uso da palavra liberdade,
>>
>> a qual será suprimida dos dicionários
>>
>> e do pântano enganoso das bocas.
>>
>> A partir deste instante
>>
>> a liberdade será algo vivo e transparente
>>
>> como um fogo ou um rio,
>>
>> e a sua morada será sempre
>>
>> o coração do homem."
>>
>> (Thiago de Mello)
>>
>>
>>
>> 	[[alternative HTML version deleted]]
>>
>>
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list