0

I'm trying to convert a string in this format 12 Mar 1995 in a datetime object. I'm using the as.Date function, it works pretty well but, if I try to convert the string 18 Dec 1856 the function returns me NA. I tried changing different parts of the string and I discovered that some month abbreviation do not work. For instance, if I try to convert 18 Dec 1856 or 18 Jul 1856 it doesn't work, but if I want to convert 18 Mar 1956 or 18 May 1956 it works. What am I doing wrong? Here is the code that I'm using:

myDate="18 Dec 1956" as.Date(myDate, format="%d %b %Y")

Giuseppe Minardi
  • 411
  • 4
  • 16
  • 2
    The `%b` part of the format is locale-specific. If you are working on a system with Italian or other encoding, the English abbreviations will (mostly) not be interpreted correctly. Maybe try changing the locale as per this question where somebody was trying to read Spanish months in a US language locale - https://stackoverflow.com/questions/32057148/r-read-abbreviated-month-form-a-date-that-is-not-in-english – thelatemail Dec 09 '18 at 00:57
  • Thank you! Now it works, I wasted an entire day on this – Giuseppe Minardi Dec 09 '18 at 01:20

0 Answers0