xldate: Convert Excel Number to Date

View source: R/xldate.R

xldateR Documentation

Convert Excel Number to Date

Description

Converts dates formatted as long integers from Excel to Date format in R, accounting for known Excel leap year errors. Author: Bryce Chamberlain. Tech review: Dominic Dillingham.

Usage

xldate(
  x,
  origin = "1899-12-30",
  nastrings = easyr::nastrings,
  preprocessed.values = NULL,
  ifna = c("return-unchanged", "error", "warning", "return-na"),
  verbose = TRUE,
  allow_times = FALSE,
  do.month.char = TRUE,
  min.acceptable = lubridate::ymd("1920-01-01"),
  max.acceptable = lubridate::ymd("2050-01-01")
)

Arguments

x

Vector of values.

origin

Zero value to use in date conversion. Older version of excel might use a different value.

nastrings

Vector of characters to be considered NAs. todate will treat these like NAs. Defaults to the easyr::nastrings list.

preprocessed.values

Strings need to have NAs set, lowercase and be trimmed before they can be checked. To avoid doing this twice, you can tell the function that it has already been done.

ifna

Action to take if NAs are created. 'return-unchanged' returns the sent vector unchanged; 'warning' results in a warning and returns the converted vector with new NAs; 'error' results in an error.

verbose

Choose to view messaging.

allow_times

Return values with time, not just the date.

do.month.char

Convert month character names like Feb, March, etc.

min.acceptable

Set NA if converted value is less than this value. Helps to prevent numbers from being assumed as dates. Set NULL to skip this check.

max.acceptable

Set NA if converted value is greater than this value. Helps to prevent numbers from being assumed as dates. Set NULL to skip this check.

Value

Vector of converted values.

Examples

xldate( c('7597', '42769', '47545', NA ) )

easyr documentation built on March 31, 2023, 6:22 p.m.

Related to xldate in easyr...