dttm_to_dt: Coerce Datetimes to Dates if No Information is Lost

View source: R/std_date.R

dttm_to_dtR Documentation

Coerce Datetimes to Dates if No Information is Lost

Description

dttm_to_dt() converts POSIXt objects to Date objects when there is no additional information contained in the POSIXt format (i.e. there is no sub-daily information).

Usage

dttm_to_dt(.x, force = c("none", "dt", "dttm"))

Arguments

.x

A Date, POSIXct or POSIXlt (i.e. a datetime) vector

force

Whether to force conversion to Date (force = "dt") or POSIXct (force = "dttm"). The default is no forcing (force = "none").

Details

Specifically, dttm_to_dt checks whether all sub-daily information is the same for each value in the datetime vector. If so, no additional information is gained by using a POSIXt format over the simpler Date format, and the data is coerced.

If the input is scalar (i.e. has length 1L), then no conversion is attempted

Value

Either a POSIXct vector or a Date vector


jesse-smith/coviData documentation built on Jan. 14, 2023, 11:08 a.m.