1. Learn
  2. /
  3. Courses
  4. /
  5. Working with Dates and Times in R

Exercise

How long has it been?

To get finer control over a difference between datetimes use the base function difftime(). For example instead of time1 - time2, you use difftime(time1, time2).

difftime() takes an argument units which specifies the units for the difference. Your options are "secs", "mins", "hours", "days", or "weeks".

To practice you'll find the time since the first man stepped on the moon. You'll also see the lubridate functions today() and now() which when called with no arguments return the current date and time in your system's timezone.

Instructions

100 XP
  • Apollo 11 landed on July 20, 1969. Use difftime() to find the number of days between today() and date_landing.
  • Neil Armstrong stepped onto the surface at 02:56:15 UTC. Use difftime() to find the number of seconds between now() and moment_step.