0

I have a date-time character:

"01.01.2010 00:00"

I parse it to POSIXct and set time zone:

df$date = as.POSIXct(df$date, format = "%m.%d.%Y %H:%M", tz = "Europe/Helsinki" )

and got

"2010-01-01 EET"

Then I tried to convert it to Date:

as.Date(df$date[1], format = "%m.%d.%Y")

However, I got the previous date:

"2009-12-31"

I understand that problem lies somewhere in time zones, so I tried to format everything to tz = "Europe/Helsinki" and it did not work. Can you help to solve the problem?

Henrik
  • 65,555
  • 14
  • 143
  • 159
Priit Mets
  • 465
  • 2
  • 14
  • 2
    You're correct. The issue, not necessarily a problem, is in the timezones. `as.Date` uses a default timezone of UTC. You created your date column using EET. Then you converted your data frame date to another date, using UTC. UTC is (usually) one hour behind EET, so midnight on any given day (EET) is 11pm the day before UTC. Your code is working as expected. whether it's working correctly is a different matter, and you haven't given us enough information to know that. What timezone was used to record your input data? if you don't know that, you'll have to make assumptions. – Limey Mar 04 '21 at 10:19
  • You say "it did not work". How did it not work? How did what happened differ from what you expected? Did you get an error message? what did you expect to happen? – Limey Mar 04 '21 at 10:22

0 Answers0