0

I have a date character string of "m/d/y hours:min" that I want to convert to just the mdy portion. I have

##to pull just the date portion## voa$dateonly = substr(voa$date,1,10)

##convert to date## voa$dateonly <- as.Date(voa$dateonly)

But it's returning with two leading zeros at the front and not the complete date as if it's thinking the month is the year (0011-10-20) but in reality the date I need is 11-11-2021. How do I fix this? Date is the full datetime variable and dateonly is the variable I'm trying to create.

  • 1
    Try `as.Date(voa$dateonly, format = "%m/%d/%Y")` if your years are in the format `1986` or `as.Date(voa$dateonly, format = "%m/%d/%y")` if they are in the format `86` – Allan Cameron May 09 '22 at 16:52
  • Please show what your data actually looks like. E.g. `head(voa$dateonly)`. – Axeman May 09 '22 at 16:55

0 Answers0