Nick Nick - 8 months ago 54
R Question

Specific kind of date conversion in R

I have looked through the site and cannot find a way to convert a date into a specific format that I need in order to properly read file names. Any help would be appreciated. I am trying to get from the standard date format


to the date format of


My current attempt is

date <- as.Date("2013-06-01")
newdate <- paste(month(date),day(date),year(date))

But that leaves me with a date of


How can I make sure that I keep the 0's in the new date format?

Answer Source

We can use format

format(date, "%m%d%Y")
#[1] "06012013"


date <- as.Date("2013-06-01")