0

How do you change this date format 2020/02/06T08:14:26z into something "simpler date" in Rstudio?

notice the "z" is a small letter

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161

2 Answers2

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

Pawan Rama Mali
  • 526
  • 2
  • 9
2

Another option is chron package - it's nice, simple and what matters the most, it will do the job.

If you don't have chron installed, do:

 install.packages("chron")
 # load it
 library(chron)
 # make dummy data
 bdate <- c("09/09/09", "12/05/10", "23/2/09")
 wdate <- c("12/10/09", "05/01/07", "19/7/07")
 ddate <- c("2009-09-27", "2007-05-18", "2009-09-02")
 # notice the last argument, it will not allow creation of factors!
 dtf <- data.frame(id = 1:3, bdate, wdate, ddate, stringsAsFactors = FALSE)
 # since we have characters, we can do:
 foo <- transform(dtf, bdate = chron(bdate, format = "d/m/Y"), wdate = chron(wdate, format = "d/m/Y"), ddate = chron(ddate, format = "y-m-d"))
 # check the classes
 sapply(foo, class)
 # $id
 # [1] "integer"

 # $bdate
 # [1] "dates" "times"

 # $wdate
 # [1] "dates" "times"

 # $ddate
 # [1] "dates" "times"
Pawan Rama Mali
  • 526
  • 2
  • 9