-4

For example:

if I have

x <- "2016-11-23 16:22:03 IST"
y <- "2016-11-23 16:28:29 IST"

how can I calculate how much time has left between them?

  • 1
    First, convert the characters to datetime objects, then take the difference between the two. Could be `diff(lubridate::ymd_hms(c(x, y)))`. But there are other options. – lukeA Nov 23 '16 at 12:13
  • 3
    `as.POSIXct(x) - as.POSIXct(y)` or `difftime(as.POSIXct(x), as.POSIXct(y))` ? – David Arenburg Nov 23 '16 at 12:15

1 Answers1

4

Try this:

x <- strptime("2016-11-23 16:22:03 IST", format = '%Y-%m-%d %H:%M:%S') 
y <- strptime("2016-11-23 16:28:29 IST", format = '%Y-%m-%d %H:%M:%S')

y-x
#Time difference of 6.433333 mins
Sandipan Dey
  • 21,482
  • 2
  • 51
  • 63
  • 1
    Please avoid answering duplicated questions. I understand you have answered before it was marked as dupe. Simple search for "r date time difference" would give many many already existing posts on this topic. – zx8754 Nov 24 '16 at 19:42