Parse a Date Column

parse_date_col(
  data,
  col,
  quiet = TRUE,
  tz = NULL,
  locale = Sys.getlocale("LC_TIME")
)

Details

Includes evaluation of the variables as dates with origins of 1900-01-01 and 1970-01-01. Since the evaluation of origin is temperamental (ie 91884 is parsed into a date in 1997 which would be difficult to weed out downstream since it is a realistic date), it is not coalesced with the other parsed columns and is reported separately in the output.

See also

Examples

library(tidyverse) test_data <- tibble(A = c("91884", "", NA, "091884", "09984", "090984", "09/18/1984", "1984-09-18", "9/18/84", "9/9/84", "9-9-84", "9-18-84", "12-18-84")) test_data %>% parse_date_col(A)
#> # A tibble: 13 x 9 #> A ymd mdy ydm myd dmy dym #> <chr> <date> <date> <date> <date> <date> <date> #> 1 "918… NA NA NA NA NA NA #> 2 "" NA NA NA NA NA NA #> 3 NA NA NA NA NA NA NA #> 4 "091… NA 1984-09-18 NA NA NA NA #> 5 "099… NA NA NA NA NA NA #> 6 "090… NA 1984-09-09 NA NA 1984-09-09 NA #> 7 "09/… NA 1984-09-18 NA NA NA NA #> 8 "198… 1984-09-18 NA NA NA NA NA #> 9 "9/1… NA 1984-09-18 NA NA NA NA #> 10 "9/9… NA 1984-09-09 NA NA 1984-09-09 NA #> 11 "9-9… NA 1984-09-09 NA NA 1984-09-09 NA #> 12 "9-1… NA 1984-09-18 NA NA NA NA #> 13 "12-… NA 1984-12-18 NA NA NA NA #> # … with 2 more variables: origin_19700101 <date>, origin_19000101 <date>