I am trying to parse a date from a Spanish date format but it fails being my system language English (on Windows 10). Bellow an example:
Sys.getlocale()
dmy('20 diciembre 2023')
dmy('20 december 2023')
month.name
I have found other posts addressing a similar issue but none of the proposed solutions solves my problem, here:
- https://stackoverflow.com/questions/71278155/r-converting-datetime-format-in-foreign-language-not-working
- https://github.com/tidyverse/lubridate/issues/781
Even after Sys.setlocale() it keeps failing. I have tried all these three:
Sys.setlocale("LC_TIME", "Spanish_Spain.1252")
Sys.setlocale("LC_TIME", "es_ES")
Sys.setlocale("LC_TIME", "Spanish")
Furthermore, curiously enough Sys.setlocale("LC_TIME", "Spanish_Spain.1252") parsed correctly the date format for each month but for 'diciembre'.
Sys.getlocale()
dmy('20 diciembre 2023')
dmy('20 december 2023')
month.name
dmy('20 enero 2023')
dmy('20 january 2023')
Please, I really appreciate any inputs. Thanks!
Here is the output from the code above:
First:
> Sys.getlocale()
[1] "LC_COLLATE=English_United States.utf8;LC_CTYPE=English_United States.utf8;LC_MONETARY=English_United States.utf8;LC_NUMERIC=C;LC_TIME=Spanish_Spain.1252"
> dmy('20 diciembre 2023')
[1] NA
Warning message:
All formats failed to parse. No formats found.
> dmy('20 december 2023')
[1] "2023-12-20"
> month.name
[1] "January" "February" "March" "April" "May"
[6] "June" "July" "August" "September" "October"
[11] "November" "December"
>
Last:
> Sys.setlocale("LC_TIME", "Spanish_Spain.1252")
[1] "Spanish_Spain.1252"
> Sys.getlocale()
[1] "LC_COLLATE=English_United States.utf8;LC_CTYPE=English_United States.utf8;LC_MONETARY=English_United States.utf8;LC_NUMERIC=C;LC_TIME=Spanish_Spain.1252"
> dmy('20 diciembre 2023')
[1] NA
Warning message:
All formats failed to parse. No formats found.
> dmy('20 december 2023')
[1] "2023-12-20"
> month.name
[1] "January" "February" "March" "April" "May"
[6] "June" "July" "August" "September" "October"
[11] "November" "December"
> dmy('20 enero 2023')
[1] "2023-01-20"
> dmy('20 january 2023')
[1] "2023-01-20"