0

I have a file that gives me the date along with the time in the column.

I only want the date, but in Year-month-day format.

vmax1$date <- substr(vmax1$date,1,10)

myformat <- "%y-%m-%d" vmax1$date<-as.Date(vmax1$date,myformat) str(vmax1)

Here is the code I use, but it just changes the date column to NAs instead of the correct format enter image description here

  • 1
    The format should match the one in the data. It should be `%d/%m/%Y` and not `%y-%m-%d` where %d stands for day, %m- month and %Y- four digit year – akrun Mar 22 '21 at 22:58
  • When I do that it changes the day of the month to the year? How to I fix that? – Ben McCarthy Mar 23 '21 at 23:39
  • I am not able to replicate `as.Date('19/03/2021 10:05', '%d/%m/%Y')# [1] "2021-03-19"` – akrun Mar 23 '21 at 23:41

0 Answers0