calculate_time_span: Function to calculate time span between dates.

View source: R/calculate_time_span.R

calculate_time_spanR Documentation

Function to calculate time span between dates.

Description

Function to calculate time span between dates.

Usage

calculate_time_span(
  date_one,
  date_two,
  format = c("seconds", "hms", "duration", "period", "days"),
  round = NA,
  as.character = FALSE
)

Arguments

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.

Value

Vector length of 1. Can be of type numeric, hms, duration, period, or character.

Author(s)

Stuart K. Grange.

Examples


# 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)


skgrange/threadr documentation built on April 15, 2024, 9:35 p.m.