Skip to content

Handling dates

4 messages · Göran Broström, Peter Dalgaard, Thomas Lumley

#
I have a problem with some functions handling dates, in packages 'date' and 
'survival' (they seem to be identical). For instance, from the documentation,

--------------------
mdy.date {survival}	

R Documentation

Convert to Julian Dates

Description

Given a month, day, and year, returns the number of days since January 1, 1960.
Usage

mdy.date(month, day, year, nineteen = TRUE, fillday = FALSE,
         fillmonth = FALSE)
----------------------------
but
[1] 1Dec77

Similar strange results appear in other date-related functions. I plan to 
write functions that converts, eg, "1977-01-31" to the real number 1977.084
and back. What function in  R  does what 'mdy.date' claims to do?

I'm on
  
platform i686-pc-linux-gnu
arch     i686
os       linux-gnu
system   i686, linux-gnu
status
major    2
minor    1.1
year     2005
month    06
day      20
language R
#
G??ran Brostr??m <gb at stat.umu.se> writes:
mdy.date does ...
structure(6544, class = "date")
[1] 1977.085

But with recent R's, as.Date is a better bet:
[1] 1977.084

(notice that you need the c() to avoid the nonsense of
Time difference of 1977.084 days

)
#
On Fri, Aug 19, 2005 at 01:35:45PM +0200, Peter Dalgaard wrote:
Thanks, I should have remembered that what functions print and what they 
return can be quite different things. This one returns "Julian dates".  
Which can be seen under "Value". But isn't the Description a bit misleading?
What I want is that the the fraction (0.084) should be equal to the fraction 
of the full year 1977 that is spent between 1977-01-01, at 00:00:00 and
1977-01-31, at noon. I know how to do it now.

Thanks again, G??ran
#
On Fri, 19 Aug 2005, [iso-8859-1] Göran Broström wrote:
Well, mdy.date does (the result *prints* as a date, but works in numerical 
operations).  Eg
[1] 1987.916



 	-thomas