0

I want to convert this column to date as %m-%d-%Y-HMS, and remove the milliseconds. How to do this?

df <- tribble(
 ~date,   
   "Februar 1st 2021, 06:34:53.190",
)

Thanks in advance.

datazang
  • 989
  • 1
  • 7
  • 20

1 Answers1

1

If you have locale same as the data that you have using lubridate's mdy_hms should work.

df$date <- lubridate::mdy_hms(df$date)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • Thanks a lot for your comment. It gives me the following error: All formats failed to parse. No formats found. – datazang Feb 10 '21 at 10:30
  • I think 190 (a millisecond) should be removed first or? – datazang Feb 10 '21 at 10:32
  • Nope. This is locale dependent. `lubridate::mdy_hms("February 1st 2021, 06:34:53.190")` works for me. "Februar" I guess is in German? You need to change your locale accordingly. See this answer https://stackoverflow.com/a/49154187 which might help you do that. – Ronak Shah Feb 10 '21 at 10:33