new_duration(second = 3690)
# Time difference of 1.025 hours
new_period(second = 3690)
# 3690 seconds
new_period(second = 30, minute = 1, hour = 1)
# 1 hour, 1 minute and 30 seconds
new_interval(as.POSIXct("2009-08-09 12:00:00"), as.POSIXct("2009-08-09 13:01:30"))
# [1] 1.025 hours beginning at 2009-08-09 12:00:00
date <- as.POSIXct("2009-03-08 01:59:59") # DST boundary
# "2009-03-08 01:59:59 CST"
date + days(1)
# "2009-03-09 01:59:59 CDT" periods preserve clock time
date + edays(1)
# "2009-03-09 02:59:59 CDT" durations preserve exact passage of time
date2 <- as.POSIXct("2000-02-29 12:00:00")
date2 + years(1)
# "2001-02-28 12:00:00 CST"
# self corrects to most recent real day
date3 <- as.POSIXct("2009-01-31 01:00:00")
date3 + c(0:11) * months(1)
# [1] "2009-01-31 01:00:00 CST" "2009-02-28 01:00:00 CST"
# [3] "2009-03-31 01:00:00 CDT" "2009-04-30 01:00:00 CDT"
# [5] "2009-05-31 01:00:00 CDT" "2009-06-30 01:00:00 CDT"
# [7] "2009-07-31 01:00:00 CDT" "2009-08-31 01:00:00 CDT"
# [9] "2009-09-30 01:00:00 CDT" "2009-10-31 01:00:00 CDT"
#[11] "2009-11-30 01:00:00 CST" "2009-12-31 01:00:00 CST"
span <- date - date2 #creates interval
# 3294.583 days beginning at 2000-02-29 12:00:00
span - days(294)
# 3000.542 days beginning at 2000-02-29 12:00:00
span - edays(294.542)
# 3000 days beginning at 2000-02-29 12:00:00
date <- as.POSIXct("2009-01-01 00:00:00")
# "2009-01-01 GMT"
date + years(1)
# "2010-01-01 GMT"
date - days(3) + hours(6)
# "2008-12-29 06:00:00 GMT"
date + 3 * seconds(10)
# "2009-01-01 00:00:30 GMT"
months(6) + days(1)
# 6 months and 1 day}
Run the code above in your browser using DataLab