The standard answer is to use
> as.POSIXlt("2007-05-14") - as.POSIXlt("1950-01-01")
Time difference of 20952 days
If you want to ensure the time difference is in daily units, then
> difftime(as.POSIXlt("2007-05-14"),
as.POSIXlt("1950-01-01"), units = "days")
Time difference of 20952 days
If you want to use the answer in numerical computations, then one more
coercion is usually needed
> as.numeric(difftime(as.POSIXlt("2007-05-14"),
as.POSIXlt("1950-01-01"), units "days"))
[1] 20952
Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary): +61 7 3826 7304
Mobile: (I don't have one!)
Home Phone: +61 7 3286 7700
mailto:Bill.Venables at csiro.au
http://www.cmis.csiro.au/bill.venables/
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of threshold
Sent: Monday, 14 May 2007 7:16 PM
To: r-help at stat.math.ethz.ch
Subject: [R] number of days
Hi, some of you knows how to calculate in R the number of days between
given
dates?
issue relevant in option pricing
thanks, robert
--
View this message in context:
http://www.nabble.com/number-of-days-tf3751163.html#a10600371
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.