Re: [R] Default Format for Dates?

From: Gabor Grothendieck <>
Date: Sat 11 Jun 2005 - 04:18:04 EST

On 6/10/05, <> wrote:
> Is there anyway to preset date formats? I have a date from a cover.dbf
> that is shown as this:
> > cover$FINALREPOR
> [1] "2003-06-24"
> The numeric value in cover$FINALREPOR is 12227. I'd rather not create
> another vector to hold the properly formatted date.
> When I put this in a WordPerfect merge, I want the date to be June 24,
> 2003. I could take care of the problem in a WordPerfect macro but I'd
> rather do it as an R default date format if possible.

I am not entirely sure I understand what you are asking but I assume you want a Date variable such that print, format and as.character, when applied to it, produce default output of a prespecified format.

Although I do not think Date will do that, chron can associate a default format with a chron variable.


# custom format for a dates (i.e. chron) object my.format <- function(x) format(as.Date(dates(x)), "%B %d %Y")

# test data
my.Date <- Sys.Date() + 0:9

# convert to chron and associate my.format to it my.chron <- chron(unclass(my.Date), out.format = my.format)


Note that you can find more information on chron and various conversions in my article in RNews 4/1 and especially the table at the end of that article. mailing list PLEASE do read the posting guide! Received on Sat Jun 11 04:26:25 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:30 EST