-1

I am trying to convert the date-time character string "29.04.2023 06:08:01.165" using the POSIXct function, however I only get null values when I try to convert the whole thing:

test <- "29.04.2023 06:08:01.165"
z <- as.POSIXct(test,format="%d-%m-%Y %H:%M:%OS")
z
[1] NA

What am I doing wrong? It works fine when I just try to return it to the second, but I need the milliseconds.

Thanks in advance for your help!

  • 1
    I don't see dashes in your `test` string - you have dots `.` as separators and the `format=` needs to match exactly. I can't see how it would have worked with just the seconds either. – thelatemail Jun 15 '23 at 20:51

1 Answers1

0

This should correctly convert the date string to a POSIXct object.

z <- as.POSIXct(test, format = "%d.%m.%Y %H:%M:%OS")

test <- "29.04.2023 06:08:01.165"
    z <- as.POSIXct(test, format = "%d.%m.%Y %H:%M:%OS")

this is the result:

z
[1] "2023-04-29 06:08:01.164 CEST"
VR28
  • 184
  • 6