Skip to Content

convert difftime time to years, months and days

How can I accurately convert the products (units is in days) of the difftime below to years, months and days?


This does years and days but how could I include months?

yd.conv<-function(days, print=TRUE){
    if (print) cat(x2,"years &",x4,"days\n")
    invisible(c(x2, x4))

I'm not sure how to even define months either. Would 4 weeks be considered a month or the passing of the same month day. So for the later definition of a month if the initial date was 2012-01-10 and the current 2012-05-31 then we'd have 0 years, 5 months and 21 days. This works well but what if the original date was on the 31st of the month and the end date was on feb 28 would this be considered a month?

As I wrote this question the question itself evolved so I'd better clarify:

What would be the best (most logical approach) to defining months and then how to find diff time in years, months and days?