Skip to content
Prev 198821 / 398506 Next

question about difference in date objects

On Mon, 2 Nov 2009, Phil Smith wrote:

            
How long is a month?

difftime() can give you an answer in days, which might suffice if you 
define a month as a number of days.  Another idea is to use (untested)

getMonth <- function(x)
{
    xx <- as.POSIXlt(x)
    12*xx$year + xx$mon + (xx$mday-1)/31
}

which will convert to a (fractional) number of months since 
1900-01-01, and that can be differenced.