0

Both the following two lines of code return NA.

as.POSIXct("1-March-2021 11:45", format="%d-%B-%Y %H:%M")
as.POSIXct("1-Mar-2021 11:45", format="%d-%b-%Y %H:%M")

But if I change March to 3, it works fine.

as.POSIXct("1-3-2021 11:45", format="%d-%m-%Y %H:%M")

I am stuck here. Thanks for any hint.

thelatemail
  • 91,185
  • 12
  • 128
  • 188
Roy
  • 539
  • 1
  • 4
  • 12
  • 3
    It could be that locale settings have a different language other than english. If it is french, it could be `mars` instead of March. For me it is working `as.POSIXct("1-March-2021 11:45", format="%d-%B-%Y %H:%M")# [1] "2021-03-01 11:45:00 IST"` – akrun Apr 05 '23 at 02:43
  • 2
    Indeed. It is the language setting problem. Thanks – Roy Apr 05 '23 at 02:47

1 Answers1

1

What's your OS? This works here (on Ubuntu)

> as.POSIXct("1-March-2021 11:45", format="%d-%B-%Y %H:%M")
[1] "2021-03-01 11:45:00 CST"
> as.POSIXct("1-Mar-2021 11:45", format="%d-%b-%Y %H:%M")
[1] "2021-03-01 11:45:00 CST"
> 

Localization may matter too. I am in a US-English one:

> Sys.getenv("LANG")
[1] "en_US.UTF-8"
> 
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725