Skip to content
Prev 86931 / 398506 Next

Number of Days Between Dates: Incorrect Results For Date Calucations.

In some cases, incorrect results are produced by the code below intended to
calculate the number of days between 2 dates.  The year in question was a
leap year.

Note the results for 2004-04-04 and 2004-04-05 are the same! They should be
37 and 38 respectively.
[1] 35
[1] 36
[1] 37
[1] 37
[1] 38
as.POSIXct("2004-02-27"),units="days"))
[1] 38
as.POSIXct("2004-02-27"),units="days"))
[1] 37
as.POSIXct("2004-02-27"),units="days"))
[1] 37

It appears that difftime() and "-" are producing invalid results.


Regards,

Gerald Herbert