Nick Nick - 3 days ago 5
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

2013-06-01


to the date format of

06012013


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

612013


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

Answer

We can use format

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

where

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