Smith, Phil
2006-Mar-10 18:20 UTC
[R] difference between 2 dates: IN MONTHS the way Mothers compute it
Hi R-people: I need a function to compute the number of months between 2 dates, in the same way a mother would do it. For example, if a kid is born on February 6, the number of months between that date and March 7 is exactly 1 month, although it is only 29 days. Thank you! Phil Smith CDC [[alternative HTML version deleted]]
Gabor Grothendieck
2006-Mar-10 18:38 UTC
[R] difference between 2 dates: IN MONTHS the way Mothers compute it
zoo has the "yearmon" class which will convert a date to a year +
0/12 to 11/12 to represent the month, disregarding the day, so:
library(zoo)
12 * as.numeric((as.yearmon("2006-03-07") -
as.yearmon("2006-02-06"))) # 1
On 3/10/06, Smith, Phil <pzs6 at cdc.gov> wrote:> Hi R-people:
>
> I need a function to compute the number of months between 2 dates, in the
same way a mother would do it.
>
> For example, if a kid is born on February 6, the number of months between
that date and March 7 is exactly 1 month, although it is only 29 days.
>
> Thank you!
> Phil Smith
> CDC
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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
>
davidr at rhotrading.com
2006-Mar-10 20:52 UTC
[R] difference between 2 dates: IN MONTHS the way Mothers compute it
I just solved this for dealing with deliverables for the CBOT's treasury
futures.
length(seq(from=x, to=y, by="months"))-1
David L. Reiner
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-
> bounces at stat.math.ethz.ch] On Behalf Of Smith, Phil
> Sent: Friday, March 10, 2006 12:20 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] difference between 2 dates: IN MONTHS the way Mothers
compute> it
>
> Hi R-people:
>
> I need a function to compute the number of months between 2 dates, in
the> same way a mother would do it.
>
> For example, if a kid is born on February 6, the number of months
between> that date and March 7 is exactly 1 month, although it is only 29 days.
>
> Thank you!
> Phil Smith
> CDC
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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