In the exercises below, we will continue our work with the lubridate package to see more features of it.

Answers to these exercises are available here.

If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.

**Exercise 1**

Lubridate offers two functions to see the date and date-time, at the moment, in the system. Use them to see the time in your time zone.

**Exercise 2**

There is a base function named “difftime” to find time difference between two times. Now use this to find out the time difference in weeks between.

` x <- "11 th april 2012" `

` y <- "April 24th 2018 11:59:59" `

**Exercise 3**

Do the same as above and find the difference between the system time and x, in hours.

**Exercise 4**

Lets say we have:

` x <- "11 th april 2018 11.30.00" `

We want to add one day to x. How do we achieve that?

**Exercise 5**

Now add 100 hours to x and find which date-time it is.

**Exercise 6**

Now, how can we get the date-time of 3 weeks prior to x?

**Exercise 7**

Now, read about the duration and spans from lubridate’s vignette. Try getting the date-time 10 years prior to x first by subtracting with years and then by using 10 year duration’s. See if they are similar and try to reason it.

**What's next:**

- Become a Top R Programmer Fast with our Individual Coaching Program
- Explore all our (>4000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below

## Leave a Reply