My session is in Spanish. When I have a format with full month name (%B
) I get the correct date:
as.Date("01-Febrero-2021", format = "%d-%B-%Y")
# [1] "2021-02-01"
However, when I try to use the abbreviated month (%b
), I get an "NA":
as.Date("01-Feb-2021", format = "%d-%b-%Y")
# [1] NA
as.Date("01-feb-2021", format = "%d-%b-%Y")
# [1] NA
as.Date("01-FEB-2021", format = "%d-%b-%Y")
# [1] NA
What I'm doing wrong?
Thanks to the answer from G. Grothendieck, I could make it work:
Sys.getlocale("LC_TIME")
# [1] "Spanish_Argentina.1252"
When checking the abbreviated month using format
on Sys.Date
, it turns out that the month is written with a period:
format(Sys.Date(), "%b")
# [1] "feb."
Try to parse a string, this time with a period:
as.Date("01-feb.-2021", format = "%d-%b-%Y")
# [1] "2021-02-01"
Works!