Handling date and date-time in R

Be careful with the time zone

> example = as.POSIXct(“1957-09-30 16:00:00”)

> example

[1] “1957-09-30 16:00:00 PST”

> as.Date(example)

[1] “1957-10-01”

> as.Date(example, tz = Sys.timezone())

[1] “1957-09-30”

The problem is that as.POSIXct() uses system timezone as default time zone and as.Date() uses UTC as default timezone.

Leave a Comment

Filed under ScriptingMemo

Leave a Reply

Your email address will not be published. Required fields are marked *