View source: R/calculate_time_span.R
calculate_time_span | R Documentation |
Function to calculate time span between dates.
calculate_time_span(
date_one,
date_two,
format = c("seconds", "hms", "duration", "period", "days"),
round = NA,
as.character = FALSE
)
date_one |
First date. |
date_two |
Second date. |
format |
Type of return. |
round |
Number of digits to round return to. |
as.character |
Should the return be a character vector. |
Vector length of 1. Can be of type numeric, hms, duration, period, or character.
Stuart K. Grange.
# Define some dates
date_one <- lubridate::ymd_h("2019-02-03 5", tz = "UTC")
date_two <- lubridate::ymd_hms("2019-04-12 6:54:55.98565", tz = "UTC")
# Find spans in different formats
# Seconds as default
calculate_time_span(date_one, date_two)
# Other formats
calculate_time_span(date_one, date_two, format = "hms")
calculate_time_span(date_one, date_two, format = "duration")
calculate_time_span(date_one, date_two, format = "period")
calculate_time_span(date_one, date_two, format = "days")
# Use round to reduce precision
calculate_time_span(date_one, date_two, format = "period", round = 0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.