Skip to content
Prev 68513 / 398506 Next

How to transform the date format as "20050425"

On Mon, 2005-04-25 at 15:18 -0500, Yong Wang wrote:
If you are just formatting the Date (ie. no time component) then look
at ?as.Date, which has a format argument:
[1] "2005-04-25"

Using the format argument, you then return a standard Date class object
for use in R. The format argument varies as required for your data
format.

On the output side, there is the format() function, which has a method
for Dates, that you can then use to convert the Date class object into a
character vector:
[1] "2005-04-25"
[1] "April 25 2005"

Also see ?strftime for details on date format strings.

HTH,

Marc Schwartz