I have two datetime objects of class POSIXct as follows:
> x = as.POSIXct('2013-03-31 01:39:42')
> y = as.POSIXct('2013-03-31 03:11:24')
The time difference of the two datetimes is calculated as 31.7 minutes (or 1902 seconds).
> y - x
Time difference of 31.7 mins
However, the time difference in this case is 91.7 minutes (or 5502 seconds). Can someone please explain to me this error?
Have you ever heard of daylight saving time?
x
#[1] "2013-03-31 01:39:42 CET"
y
#[1] "2013-03-31 03:11:24 CEST"
Look at the time zones.
Compare with this:
x = as.POSIXct('2013-03-31 01:39:42', tz="GMT")
y = as.POSIXct('2013-03-31 03:11:24', tz="GMT")
y-x
#Time difference of 1.528333 hours