[R] time difference (from date function)

jim holtman jholtman at gmail.com
Wed Mar 18 17:24:36 CET 2009


If what you have is a character string, then convert it to POSIXlt and
use difftime:

> x1
[1] "Wed Mar 18 12:18:11 2009"
> x2
[1] "Wed Mar 18 12:18:18 2009"
> x1.c <- strptime(x1, "%a %b %d %H:%M:%S %Y")
> x2.c <- strptime(x2, "%a %b %d %H:%M:%S %Y")
> difftime(x2.c, x1.c, units='secs')
Time difference of 7 secs
>


On Wed, Mar 18, 2009 at 12:03 PM, milton ruser <milton.ruser at gmail.com> wrote:
> Dear all,
>
> I have two variables which contents are date() function answers, like:
>
> d1<-date()
> d2<-date()
>
> Now I need to compute the difference between d2 and d1 (in minutes).
>
> Any help are welcome.
>
> Best wishes
>
> miltinho
> brazil
>
>        [[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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list