difftime.days: Compute Time Difference In Days

difftime.daysR Documentation

Compute Time Difference In Days

Description

Computes the number of days between two vectors of class Date or POSIXt. In the latter case, the time portion is ignored.

Usage

difftime.days(time1, time2)

Arguments

time1, time2

Two vectors of the same length, both either of class Date or POSIXt.

Details

This function considers the calendar date portion of a POSIXt object only. Thus, a day need not correspond to a 24 hour period (see example).

Value

An integer vector containing the number of days between time1 and time2.

Author(s)

Benjamin Rich <mail@benjaminrich.net>

See Also

difftime.default difftime

Examples

## Not run: 
time1 <- strptime("2011-12-22 00:03", "
time2 <- strptime("2011-12-22 00:01", "
time3 <- strptime("2011-12-21 23:59", "
time4 <- strptime("2011-12-20 00:01", "
difftime.days(time1, time2)  # 2 minutes difference, on the same day so considered 0 days 
difftime.days(time2, time3)  # Also 2 minutes difference but on different days, so considered one day
difftime.days(time3, time4)  # Although only 47 hours and 58 minutes difference, still considered one day

## End(Not run)

benjaminrich/PCSmisc documentation built on Feb. 11, 2024, 9:25 p.m.