0

This works:

as.Date("22JAN2010", format="%d%b%Y")
>"2010-01-22"

This doesn't:

as.Date("22MAR2010", format="%d%b%Y")
>NA

It breaks on MAR, MAY, OCT and works for JAN, FEB, APR, JUN, JUL, AUG, SEP, NOV, DEC.

Coincidentally, my Windows 7 OS language is in Dutch, for which the date abbreviations would be MAA, MEI, OKT. But those don't work either.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
DaReal
  • 597
  • 3
  • 10
  • 24

1 Answers1

-1

You can find out what monthly abbreviations are going to be recognized with the in-built data object: month.abb which is internationalized.

 month.abb
 [1] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"

The sessionInfo() function also returns the locale, which for me is:

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

... and could have gotten that single vector with Sys.getlocale() but I suspect you have something else set. As commented by @Jaap, the value is under your control with Sys.setlocale. The particular value of the 'LC_TIME' item should be used by strptime which is at the core of the as.Dat.character function.

(The Sys.setlocale function has 2 named arguments "category" and "locale" which is why the first suggestion to use Sys.setlocale(LC_TIME = "en_GB.UTF-8") failed. It seemed to be typical R syntax to my eyes as well, since the usual pairlist formalism doesn't quote the names. I've made that mistake many times.)

IRTFM
  • 258,963
  • 21
  • 364
  • 487