Please see the code below, I have to change my locale to be able to convert a date. My first attempt is unsuccessful, my second attempt works, though it seems redundant and doesn't change the output of Sys.getlocale
.
My OS is Windows 7 64-bit
Sys.getlocale() # "LC_COLLATE=French_Belgium.1252;LC_CTYPE=French_Belgium.1252;LC_MONETARY=French_Belgium.1252;LC_NUMERIC=C;LC_TIME=French_Belgium.1252"
date <- "Dec-11"
as.Date(date, format = "%b-%d") # NA
Sys.setlocale(locale = "UK") # "LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom.1252;LC_MONETARY=English_United Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252"
locale2 <- Sys.getlocale()
as.Date(date, format = "%b-%d") # NA
Sys.setlocale("LC_TIME", "English_United Kingdom")
locale3 <- Sys.getlocale() # "LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom.1252;LC_MONETARY=English_United Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252"
as.Date(date, format = "%b-%d") # "2017-12-11"
locale2 == locale3 # TRUE
I can skip the first call to Sys.getlocale
and the date conversion will work:
Sys.getlocale() # "LC_COLLATE=French_Belgium.1252;LC_CTYPE=French_Belgium.1252;LC_MONETARY=French_Belgium.1252;LC_NUMERIC=C;LC_TIME=French_Belgium.1252"
date <- "Dec-11"
as.Date(date, format = "%b-%d") # NA
Sys.setlocale("LC_TIME", "English_United Kingdom") #
locale4 <- Sys.getlocale() # "LC_COLLATE=French_Belgium.1252;LC_CTYPE=French_Belgium.1252;LC_MONETARY=French_Belgium.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252"
as.Date(date, format = "%b-%d") # "2017-12-11"
But this doesn't work :
Sys.getlocale() # "LC_COLLATE=French_Belgium.1252;LC_CTYPE=French_Belgium.1252;LC_MONETARY=French_Belgium.1252;LC_NUMERIC=C;LC_TIME=French_Belgium.1252"
date <- "Dec-11"
as.Date(date, format = "%b-%d") # NA
Sys.setlocale(locale = "English_United Kingdom") #
locale5 <- Sys.getlocale() # "LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom.1252;LC_MONETARY=English_United Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252"
as.Date(date, format = "%b-%d") # NA
This is related to this question : Converting integer format date to double format of date