Skip to content

Instantly share code, notes, and snippets.

@andilabs
Last active December 21, 2015 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andilabs/6360270 to your computer and use it in GitHub Desktop.
Save andilabs/6360270 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment