I'm trying to convert some dates in R with strptime. I've read this thread and have set my locale so that it should work. For example:
> Sys.getlocale("LC_TIME")
[1] "en_GB"
> format(Sys.time(), format="%B")
[1] "November"
However if I try to convert a month string, strptime returns NA, e.g.:
> strptime("November", format="%B")
[1] NA
I can run the example at the above link without any problem but if I simplify the example to just include the month, I get NA again.
> var <- "Thu Nov 8 15:41:45 2012"
> strptime(var, format="%a %b %d %H:%M:%S %Y")
[1] "2012-11-08 15:41:45 GMT"
> strptime("Nov", format="%b")
[1] NA
What's going on here? How can I parse a character month into a date object?
EDIT Thanks for the comments below. To clarify, this also doesn't work:
> strptime("November 2011", format="%B %Y")
[1] NA
I would also expect strptime
to fill in any missing fields with the current system time, as in strptime("2011", format="%Y")