0

I have character values that are stored like this

Date <- x("05/05/15", "06/06/15")
df <- data.frame(Date)

Now I would like to convert these dates into a format: YYYY-MM-DD but doing this:

df$Date <- format(as.Date("%d/%m/%Y", df$Date))

Does not work. Any thoughts on how I can convert it?

John Dwyer
  • 189
  • 2
  • 13

1 Answers1

1

We need to use format = "%d/%m/%y" i.e. y instead of Y as the 'year' part is only 2 digits

df$Date <- as.Date(df$Date, "%d/%m/%y") 
df$Date
#[1] "2015-05-05" "2015-06-06"

Or use lubridate

library(lubridate)
dmy(df$Date)
akrun
  • 874,273
  • 37
  • 540
  • 662