Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Dates
Summary

Instruction

Next we can calculate the difference in dates. We will use the as.period() function, which calculates the difference between the starting and ending parts of an interval object. Here it is being used on the trucks data set:

trucks$travel_duration <- as.period(trucks$travel_interval)

Exercise

Calculate total travel time using as.period() on the travel_interval column, and save it to a new column: travel_duration. We'll get a result like this:

"2y 8m 3d 18H 15M 49S"

As you can guess this means 2 years, 8 months, 3 days, 18 hours, 15 minutes, and 49 seconds. If we want to get only part of this, we can use the functions we learned earlier!