Skip to content
Prev 363153 / 398502 Next

difftime in years

Hi Thomas,
Be aware that if you are attempting to calculate "birthday age", it is
probably better to do it like this:

bdage<-function(dob,now) {
 dobbits<-as.numeric(unlist(strsplit(dob,"/")))
 nowbits<-as.numeric(unlist(strsplit(now,"/")))
 return(nowbits[3]-dobbits[3]-
  (nowbits[2]<dobbits[2] || (nowbits[2]==dobbits[2] && nowbits[1]<dobbits[1])))
}
bdage("20/09/1945","5/8/2016")

You can also do this with date objects, just add the appropriate
format arguments.

Jim


Jim

On Fri, Aug 5, 2016 at 6:35 AM, William Dunlap via R-help
<r-help at r-project.org> wrote: