parse_dates: Parse dates

View source: R/parse_dates.R

parse_datesR Documentation

Parse dates

Description

Parse dates

Usage

parse_dates(
  x,
  convert_excel = TRUE,
  orders = c("Ymd", "dmY", "dmy", "mdY", "Ymd HMS")
)

Arguments

x

A character or numeric vector of dates

convert_excel

Logical indicating whether to convert Excel-encoded date values (e.g. "42370") into dates, using janitor::excel_numeric_to_date

orders

a character vector of date-time formats. Each order string is a series of formatting characters as listed in base::strptime() but might not include the "%" prefix. For example, "ymd" will match all the possible dates in year, month, day order. Formatting orders might include arbitrary separators. These are discarded. See details for the implemented formats. If multiple order strings are supplied, they are applied in turn for parse_date_time2() and fast_strptime(). For parse_date_time() the order of applied formats is determined by select_formats parameter.

Value

A vector of class "Date". Values that cannot be converted to valid dates will be returned as ⁠<NA>⁠.

Examples

x <- c("44087", "12//02/2019", "2020_05_14", "2021-01-30 14:00:04")
parse_dates(x)


epicentre-msf/dbc documentation built on Oct. 24, 2023, 9:25 p.m.