September trouble [🇷 for BE/BA]
Hi ElMaestro,
On my system
but
You nailed it down.
Yes,
On your setup (en_GB locale?), the system abbreviated name for September is "Sept" (a four-letter). So when you feed "01/Sep/2024" to
However,
I know it is painful, locales are driving me crazy everytime (so I stick to US years ago)
On my system
Date.str=paste0("01/", month.abb[c(1:12)], "/2024")
Date.I=as.Date(Date.str,format='%d/%b/%Y')
print(data.frame(Date.str, Date.I))
Date.str Date.I
1 01/Jan/2024 2024-01-01
2 01/Feb/2024 2024-02-01
3 01/Mar/2024 2024-03-01
4 01/Apr/2024 2024-04-01
5 01/May/2024 2024-05-01
6 01/Jun/2024 2024-06-01
7 01/Jul/2024 2024-07-01
8 01/Aug/2024 2024-08-01
9 01/Sep/2024 2024-09-01
10 01/Oct/2024 2024-10-01
11 01/Nov/2024 2024-11-01
12 01/Dec/2024 2024-12-01but
month.abb[9]
[1] "Sep"
Sys.getlocale("LC_TIME")
[1] "English_United States.utf8"
as.Date("01/Sep/2024", format = '%d/%b/%Y')
[1] "2024-09-01"
as.Date("01/Sept/2024", format = '%d/%b/%Y')
[1] NA❝ Add.: Oh dear, is %b locale-dependent? Shoot me, please. Put me out of my misery. This is not good.
You nailed it down.
Yes,
%b (and thus as.Date()) is indeed locale-dependent in R, as it relies on the C strptime() function, which pulls month abbreviations from your system's locale settings.On your setup (en_GB locale?), the system abbreviated name for September is "Sept" (a four-letter). So when you feed "01/Sep/2024" to
as.Date(format = '%d/%b/%Y'), it fails with NA because the parser doesn't recognize "Sep" as matching the expected "Sept"However,
month.abb (and month.name) are hardcoded constants in R base package, always using the three-letter forms regardless of your locale. This creates the exact mismatch you're seeing.I know it is painful, locales are driving me crazy everytime (so I stick to US years ago)
—
Kind regards,
Mittyri
Kind regards,
Mittyri
Complete thread:
- September trouble ElMaestro 2025-11-10 12:26
- September troublemittyri 2025-11-10 20:38
- More months trouble Helmut 2025-11-11 09:37
- More months trouble ElMaestro 2025-11-13 05:20
- Know the month abbreviations Helmut 2025-11-13 12:45
- Know the month abbreviations ElMaestro 2025-11-14 16:34
- Know the month abbreviations Helmut 2025-11-13 12:45
- More months trouble ElMaestro 2025-11-13 05:20
- Worse in France Ohlbe 2025-11-12 15:13
- Worse in France ElMaestro 2025-11-14 16:38
