andilabs
8/27/2013 - 11:16 PM

datatime difference in R strptime difftime

datatime difference in R strptime difftime

 x1<-"2013-03-03 23:26:46.315558" 
 x2<-"2013-03-03 23:31:53.091022"
 x1 <- strptime(x1, "%Y-%m-%d %H:%M:%OS")
 x2 <- strptime(x2, "%Y-%m-%d %H:%M:%OS")
 x2
[1] "2013-03-03 23:31:53"
 x1
[1] "2013-03-03 23:26:46"
 x2-x1
Time difference of 5.112924 mins
 as.numeric(x2-x1)
[1] 5.112924
op <- options(digits.secs = 3)
 x2
[1] "2013-03-03 23:31:53.091"
 as.numeric(x2-x1,units="secs")
[1] 306.776