How many seconds are in a day?
How many seconds are in a day? There are 24 hours in a day, 60 minutes in an hour, and 60 seconds in a minute, so there should be 24*60*60
= 86400
seconds, right?
Not always! In this exercise you'll see a counter example, can you figure out what is going on?
This exercise is part of the course
Working with Dates and Times in R
Exercise instructions
We've put code to define three times in your script - noon on March 11th, March 12th, and March 13th in 2017 in the US Pacific timezone.
- Find the difference in time between
mar_13
andmar_12
in seconds. This should match your intuition. - Now, find the difference in time between
mar_12
andmar_11
in seconds. Surprised?
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Three dates
mar_11 <- ymd_hms("2017-03-11 12:00:00",
tz = "America/Los_Angeles")
mar_12 <- ymd_hms("2017-03-12 12:00:00",
tz = "America/Los_Angeles")
mar_13 <- ymd_hms("2017-03-13 12:00:00",
tz = "America/Los_Angeles")
# Difference between mar_13 and mar_12 in seconds
difftime(___, ___, units = ___)
# Difference between mar_12 and mar_11 in seconds
difftime(___, ___, units = ___)