[R-sig-finance] Date calculations

Steve Miller steve.miller at jhu.edu
Wed Mar 22 23:36:21 CET 2006

If you use the date or survival libraries, you can do something like:
as.date("01/10/2001", "mdy"), as well as as.date(14985) -- a julian
argument. You can also go back and forth between julians and numeric vectors
with mdy.date and date.mdy.

Steve Miller 

-----Original Message-----
From: r-sig-finance-bounces at stat.math.ethz.ch
[mailto:r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of Mahesh
Sent: Wednesday, March 22, 2006 10:31 AM
To: r-sig-finance at stat.math.ethz.ch
Subject: Re: [R-sig-finance] Date calculations


I have found the following to be of use when using Date manipulations.


 tDate <- as.Date("03/22/2006", "%m/%d/%Y") ;

tDate +1    ## will give the update 03/23/2006 and so on..

Best regards,


ps: fyi: the capital Y in as.Date refers to a 4 digit year representation

On 3/21/06, P. Hinaff <patrick.henaff at kermatheano.com> wrote:
> I'm a rank beginner in R and R-metrics, but experienced in matlab and
> other languages. I'm strugling with date arithmetics in R. I'm doing
> statistical analysis on financial time series, using its, which uses
> objects to measure time. What is the best way to perform simple date
> arithmetic with these objects? I do not care about h/m/s, nor do I care
> about daylight saving time. Example of a problem I faced:
> Add one day to 3-apr-2005. (daylight saving starts on 4-apr-2005).
> If I do
> > as.POSIXct("2005-04-03") + 86400
> I get 1 a.m. on the 4th of april.
> So, I do something like
> > dt1 <- as.POSIXct("2005-04-03")
> > x1 <- timeDate(dt1)
> > x2 <- timeNdayOnOrAfter(x1, n=2)
> > dt2 <- as.POSIXct(as.POSIXlt(x2))
> There has to be something simpler!
> Another problem. The tseries and timeDate packages seem to require that
> one changes his timezone environment variable to GMT. This is not really
> possible in a corporate environment. Is there a work-around?
> Any help will be much appreciated.
> Patrick Henaff
>         [[alternative HTML version deleted]]
> _______________________________________________
> R-sig-finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance

	[[alternative HTML version deleted]]

More information about the R-sig-finance mailing list