rposixct

R transformation as.POSIXct to Date substracts one day


If I have POSIXct date in R, for example

as.POSIXct("2023-10-11 00:02:00")
"2023-10-11 00:02:00 CEST"

I get unexpected output if I transfer it to Date

as.Date(as.POSIXct("2023-10-11 00:02:00"))
"2023-10-10"

Have to say I have no idea why.


Solution

  • Specify tz (timezone) in as.Date() according to your needs and you are good to go:

    as.Date(as.POSIXct("2023-10-11 00:02:00"), tz = "Europe/Berlin")
    [1] "2023-10-11"