Take the 2-minute tour ×

I am trying to convert the dates in my data frame from yyyy-mm-dd to dd-mm-yyyy format. for example:

D <- "06.12.2012"  
as.Date(D, "%d.%m.%Y")

returns :


How can I convert it to "06-12-2012"?

share|improve this question
Just to be clear. .... Oh never mind. Read Joshua's answer. –  IShouldBuyABoat Jan 3 '13 at 22:47
@DWin: you should be proud of me, I started to type that as a comment... then I thought, "What would Dwin want me to do?" –  Joshua Ulrich Jan 3 '13 at 22:53
Shirley, yur Josh-ing me. –  IShouldBuyABoat Jan 3 '13 at 22:59
@DWin: I josh thee not. –  Joshua Ulrich Jan 3 '13 at 23:03
add comment

2 Answers

up vote 9 down vote accepted

a) Parse

   d <- as.Date( "06.12.2012", "%d.%m.%Y")

b) Format

   strftime(d, "%m-%d-%Y")


   format(d, "%m-%d-%Y")
share|improve this answer
Wow, that was quick :) –  Paul Hiemstra Jan 3 '13 at 22:31
@Dirk: think you mean strftime or format –  IShouldBuyABoat Jan 3 '13 at 22:46
Yup, but got called away to a meeting. Dreadful how life sometimes inteferes with SO :) –  Dirk Eddelbuettel Jan 3 '13 at 23:03
add comment

Strictly speaking, you can't. A Date is an integer (days since 1970-01-01) that looks like a character string when printed. The printed format for Date objects is YYYY-MM-DD because that's the ISO-8601 standard.

As @GSee mentioned in chat, you would have to re-define the print.Date method with something like:

print.Date <- function(x, max=NULL, ...) {
  if (is.null(max)) 
    max <- getOption("max.print", 9999L)
  if (max < length(x)) {
    print(format(x[seq_len(max)], "%d-%m-%Y"), max = max, ...)
  else print(format(x, "%d-%m-%Y"), max = max, ...)
share|improve this answer
add comment

Your Answer


