I have my date column formats in 01-Oct-21
and I want to change them to 01-10-2021
. Does anyone knows how to do this in R?
Thanks!
CodePudding user response:
Using base R. You might need to convert your original column into Date format using
old_date <- as.Date('01-Oct-21', format = '%d-%b-%d')
Then you use the format
function to get into what you what
format(old_date, '%d-%m-%Y')
It will look slightly different if your dates are in a data frame.
CodePudding user response:
We can use
library(lubridate)
format(dmy("01-Oct-21"), '%d-%m-%Y')
[1] "01-10-2021"