Reputation: 311
Here is just one date that I have (out of more than 6,000)
02/01/15
This is expressed as January 2nd, 2015. And I would like the date to instead look like the following,
2015/01/02
I read up on this thread: Changing date format to "%d/%m/%Y"
But unless my R does not work properly, none of the answers give the correct format, instead I get this output,
0002/01/15
Upvotes: 0
Views: 69
Reputation: 3649
The lubridate
package is very useful for date and time manipulation
library(lubridate)
x <- lubridate::dmy('02/01/15')
format(x, format = ('%Y/%m/%d'))
Upvotes: 0
Reputation: 39858
You can do:
format(as.Date("02/01/15", format = "%d/%m/%y"), "%Y/%m/%d")
[1] "2015/01/02"
Upvotes: 1