Re: [R] Units of Difference Between Two Dates

From: Uwe Ligges <ligges_at_statistik.tu-dortmund.de>
Date: Thu, 15 May 2008 14:28:44 +0200

Tom La Bone wrote:
> I would like all three of these calculations to give an answer in days (or at
> least the same units):
>

>> as.POSIXct("1971-08-01 00:00:00") - as.POSIXct("1971-08-01 00:00:00")

> Time difference of 0 secs
>> as.POSIXct("1971-08-01 12:00:00") - as.POSIXct("1971-08-01 00:00:00")

> Time difference of 12 hours
>> as.POSIXct("1971-09-01 00:00:00") - as.POSIXct("1971-08-01 00:00:00")

> Time difference of 31 days
>
> What is the best way to do this?
>
> Tom
>

  difftime(as.POSIXct("1971-08-01 00:00:00"), as.POSIXct("1971-08-01 00:00:00"), units="days")

and so on ...

Uwe Ligges



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 Thu 15 May 2008 - 16:58:50 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 Thu 15 May 2008 - 17:30:38 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.

list of date sections of archive