[R] How to convert Datetime numbers from Excel to POSIXt objects

From: Rolf Fankhauser <rolf.fankhauser_at_gepdata.ch>
Date: Fri, 14 Dec 2007 17:06:52 +0000

Hi all,

I need to compare time series data files of different time formats. I had no problems with text format using strptime. But how can I convert datetime numbers from Excel (days since 30.12.1899 00:00:00) into POSIXt objects?
For example 29770.375 should be converted to "03.07.1981 09:00:00"

I tried the following code and encountered strange results:

t1-t0 gives 29770.33 (should be 29770.375 in my opinion)
t1-t2 and t1-t3 are ok
t1-t4 gives 183.3333 (should be 183.375)
Are these rounding errors?

The R-code:

t1 <- strptime("3.7.1981 09:00:00","%d.%m.%Y %H:%M:%S")
t0 <- strptime("30.12.1899 00:00:00","%d.%m.%Y %H:%M:%S")
t2 <- strptime("3.7.1981 00:00:00","%d.%m.%Y %H:%M:%S")
t3 <- strptime("1.7.1981 00:00:00","%d.%m.%Y %H:%M:%S")
t4 <- strptime("1.1.1981 00:00:00","%d.%m.%Y %H:%M:%S")
t1 - t0
t1 - t2
t1 - t3
t1 - t4

Thanks for any help or clarifications


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. Received on Fri 14 Dec 2007 - 16:09:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 14 Dec 2007 - 18:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.