[R] Rounding in date.mdy from library(date)

Kurt Hornik Kurt.Hornik at ci.tuwien.ac.at
Tue Jan 4 09:22:38 CET 2000

>>>>> Thomas Lumley writes:

> On Mon, 3 Jan 2000, BXC (Bendix Carstensen) wrote:
>> The date library contains a function date.mdy that converts a number
>> D to the date (month,date,year as a list) at D days after 1 Jan 1960.
>> This a convention that fits in with SASs.
>> The logic would be that the result was the date at D days after
>> 1 Jan 1960 00:00:00 (which is a POINT in time as opposed to a date which 
>> is an interval), so that any D with 2<=D<3 was rounded to 3 Jan 1960
>> and so on. This is because at any time D days (i.e. D*24h) after 
>> 1.1.1960:00:00 with 2<=D<3 we would call the date "3 Jan 1960".

> I think the date package is only intended to handle integers. This is
> partly because date.mdy is _not_ a function for converting numbers to
> dates, it is a function for converting dates to a printable form.
> If you look at as.date() the truncation is already done there,

R> as.date(0)
> [1] 1Jan60
R> as.date(0.9)
> [1] 1Jan60

> so a bona fide date object will always have an integer as the time since
> 1/1/1960. In that sense the workaround is to only use date.mdy on dates,
> not on numbers.

> I agree that it might be worth extending date to allow times in
> addition to dates (in which case it probably would have to have
> information on time zones as well).  The tricky part would be parsing
> time information in character form, but there is probably GNU code for
> this.

If you want time information as well, you can use package chron (which
does not use time zones, however).

It would certainly be nice to have something for handling dates/times
which can use strftime(3) formats.  And of course, it would make sense
to build something around a data type modelled around struct tm.

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list