September trouble [🇷 for BE/BA]

posted by mittyri  – Russia, 2025-11-10 21:38 (220 d 05:05 ago) – Posting: # 24485
Views: 2,635

Hi ElMaestro,

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-01


but
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

Complete thread:

UA Flag
Activity
 Admin contact
23,654 posts in 4,992 threads, 1,570 registered users;
165 visitors (0 registered, 165 guests [including 18 identified bots]).
Forum time: 03:43 CEST (Europe/Vienna)

Actually, science starts to become interesting
only where it ends.    Justus von Liebig

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5