Difference Between Two Date-Times

Want to learn more? I recommend working through: R for Data Science, R Cookbook, and R Graphics Cookbook.

# Create two dates
the_start_of_time <- as.Date("1970-01-01")
the_end_of_time <- as.Date("2012-12-21")
# calculate the difference in the two dates
difftime(the_end_of_time, the_start_of_time, units = "auto")
Time difference of 15695 days
# calculate the difference in the two dates
difftime(the_end_of_time, the_start_of_time, units = "days")
Time difference of 15695 days
# calculate the difference in the two dates
difftime(the_end_of_time, the_start_of_time, units = "weeks")
Time difference of 2242.143 weeks