I'd been trying to look through a dataframe extracting all rows where the date component of a POSIXct column matched a certain value.I came across the following which is confusing me mightily:: as.Date(as.POSIXct(...))
doesn't always return the correct date.
> dt <- as.POSIXct('2012-08-06 09:35:23')
[1] "2012-08-06 09:35:23 EST"
> as.Date(dt)
[1] "2012-08-05"
Why is the date of '2012-08-06 09:35:23' equal to '2012-08-05?
I suspect it's something to do with different timezones being used, so noting that the timezone of dt
was 'EST' I gave this to as.Date
::
> as.Date(as.POSIXct('2012-08-06 09:35:23'), tz='EST')
[1] "2012-08-05"
But it still returns 2012-08-05.
Why is this? How can I find all datetimes in my dataframe that were on the date 2012-08-06? (as subset(my.df, as.character(as.Date(datetime), tz='EST') == '2012-08-06')
does not return the row with datetime dt
even though this did occur on the date 2012-08-06...)?
Added details: Linux 64bit (though can reproduce on 32bit), can get this on both R 3.0.1 & 3.0.0, and I am currently AEST (Australian Eastern Standard Time)
See Question&Answers more detail:os