0

I have dates and times in the character format - 05/02/2021 03:46:05 PM - that I want to convert to a Date class, keeping the same format. I tried using as.Date() but that removes the time element and posixct doesn't return a 'Date' class (unless I'm mistaken).

Any ways round this?

Also can I do apply this change to a whole column, say for example data_frame$TimeCreate?

Jean-Paul Azzopardi
  • 401
  • 1
  • 2
  • 10
  • 1
    The `Date` class, as the name suggests, stores dates, not date times, so there’s no way of converting your character strings to `Date`s without losing the time component. `asPOSIX t` returns a `datetime` Which will preserve the time component. As will `lubridate::dmy_hms` and siblings. R is vectorised by default so you’ll operate on the whole column unless you deliberately do something different. – Limey Sep 21 '22 at 03:59

0 Answers0