2

I have a vector of strings which I need to convert to dates. This only works for some of the dates which are in the format of "dd-mmm-YYYY".

Example: this works: strptime("21-Sep-2017", format = "%d-%b-%Y") This does not work and returns NA: strptime("21-Dec-2017", format = "%d-%b-%Y")

What am I doing wrong or not seeing?

Cactus
  • 864
  • 1
  • 17
  • 44

1 Answers1

6

This is because your locale is probably one where December is not abbreviated as Dec. Without changing your session settings, you could simply do

lubridate::parse_date_time("21-Dec-2017", orders = "d-b-Y", locale = "us")

[1] "2017-12-21 UTC"
erocoar
  • 5,723
  • 3
  • 23
  • 45