Im trying to find time difference between two timestamps, say, start and endtime. But the stamps are in string format :07 Mar 2016 01:00:03 PM. Can someone help how to convert this in numeric and find the time difference? Thanks
Asked
Active
Viewed 83 times
1 Answers
5
lubridate is your new best friend so download it right away to get to know her.
install.packages('lubridate')
library(lubridate)
Based on your example, use dmy_hms()
a <- dmy_hms('07 Mar 2016 01:00:03 PM')
# "2016-03-07 13:00:03 UTC"
b <- dmy_hms('08 Mar 2016 01:00:03 PM')
# "2016-03-08 13:00:03 UTC"
Then a simple subtraction could get the date diff.
b - a
# Time difference of 1 days
Or you can also use the as.numeric() use this number for calculation later.
as.numeric(b - a)
# 1