More months trouble [🇷 for BE/BA]

posted by Helmut Homepage – Vienna, Austria, 2025-11-11 10:37 (228 d 04:27 ago) – Posting: # 24487
Views: 2,694

Hi ElMaestro,

Mittyri explained it already. With my locale (German_Austria) it is even worse…
      Date.str     Date.I
1  01/Jan/2024       <NA>
2  01/Feb/2024 2024-02-01
3  01/Mar/2024       <NA>
4  01/Apr/2024 2024-04-01
5  01/May/2024       <NA>
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       <NA>
11 01/Nov/2024 2024-11-01
12 01/Dec/2024       <NA>

… because the constants month.name and month.abb give the English month names and their three letter abbreviations irrespective of the locale.
month.name
 [1] "January"   "February"  "March"     "April"     "May"       "June"     
 [7] "July"      "August"    "September" "October"   "November"  "December"

month.abb
 [1] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"

Therefore, with your code I get NAs for January, March, May, and October because they do not match my locale: Jänner (Jän), März (Mär), Mai (Mai), Oktober (Okt). With German_Germany January would match: Januar (Jan).

Does that help?

ol        <- Sys.getlocale("LC_TIME")   # save original locale
ol                                      # show it
#[1] "German_Austria.utf8"              # on my system (Win11, R 4.5.2)
loc.month <- format(seq.Date(from = as.Date("2024-01-01"),
                             to = as.Date("2024-12-01"),
                             by = "m"), "%b")
local     <- paste0("01/", loc.month[c(1:12)], "/2024")
invisible(Sys.setlocale("LC_TIME", "English"))
en        <- paste0("01/", month.abb, "/2024")
Date.I    <- as.Date(en, format = "%d/%b/%Y")
invisible(Sys.setlocale("LC_TIME", ol)) # restore original
print(data.frame(local, en, Date.I), row.names = FALSE)

       local          en     Date.I
 01/Jän/2024 01/Jan/2024 2024-01-01
 01/Feb/2024 01/Feb/2024 2024-02-01
 01/Mär/2024 01/Mar/2024 2024-03-01
 01/Apr/2024 01/Apr/2024 2024-04-01
 01/Mai/2024 01/May/2024 2024-05-01
 01/Jun/2024 01/Jun/2024 2024-06-01
 01/Jul/2024 01/Jul/2024 2024-07-01
 01/Aug/2024 01/Aug/2024 2024-08-01
 01/Sep/2024 01/Sep/2024 2024-09-01
 01/Okt/2024 01/Oct/2024 2024-10-01
 01/Nov/2024 01/Nov/2024 2024-11-01
 01/Dez/2024 01/Dec/2024 2024-12-01


I don’t know what you want to achieve but in my codes I only use the ISO-date YYYY-MM-DD (in R: "%Y-%m-%d" or simply "%F") without caring about the names of months.

format(Sys.Date(), "%Y-%m-%d"); format(Sys.Date(), "%F")
[1] "2025-11-11"
[1] "2025-11-11"


Month names and abbreviations can be interesting (check esp. the French ones):

ol   <- Sys.getlocale("LC_TIME")
from <- as.Date("2025-01-01")
to   <- as.Date("2025-12-01")
by   <- "m"
en   <- data.frame(English = month.name, abbr = month.abb)
invisible(Sys.setlocale("LC_TIME", "German_Austria"))
at   <- data.frame(Austrian = format(seq.Date(from, to, by), "%B"),
                   abbr = format(seq.Date(from, to, by), "%b"))
invisible(Sys.setlocale("LC_TIME", "German_Germany"))
de   <- data.frame(German = format(seq.Date(from, to, by), "%B"),
                   abbr = format(seq.Date(from, to, by), "%b"))
invisible(Sys.setlocale("LC_TIME", "French_France"))
fr   <- data.frame(French = format(seq.Date(from, to, by), "%B"),
                   abbr = format(seq.Date(from, to, by), "%b"))
invisible(Sys.setlocale("LC_TIME", "Danish_Denmark"))
da   <- data.frame(Danish = format(seq.Date(from, to, by), "%B"),
                   abbr = format(seq.Date(from, to, by), "%b"))
invisible(Sys.setlocale("LC_TIME", ol))
months <- cbind(en, at, de, fr, da)
print(months, row.names = FALSE, right= FALSE)

 English   abbr Austrian  abbr German    abbr French    abbr  Danish    abbr
 January   Jan  Jänner    Jän  Januar    Jan  janvier   janv. januar    jan
 February  Feb  Februar   Feb  Februar   Feb  février   févr. februar   feb
 March     Mar  März      Mär  März      Mrz  mars      mars  marts     mar
 April     Apr  April     Apr  April     Apr  avril     avr.  april     apr
 May       May  Mai       Mai  Mai       Mai  mai       mai   maj       maj
 June      Jun  Juni      Jun  Juni      Jun  juin      juin  juni      jun
 July      Jul  Juli      Jul  Juli      Jul  juillet   juil. juli      jul
 August    Aug  August    Aug  August    Aug  août      août  august    aug
 September Sep  September Sep  September Sep  septembre sept. september sep
 October   Oct  Oktober   Okt  Oktober   Okt  octobre   oct.  oktober   okt
 November  Nov  November  Nov  November  Nov  novembre  nov.  november  nov
 December  Dec  Dezember  Dez  Dezember  Dez  décembre  déc.  december  dec


Dif-tor heh smusma 🖖🏼 Довге життя Україна! [image]
Helmut Schütz
[image]

The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes

Complete thread:

UA Flag
Activity
 Admin contact
23,655 posts in 4,993 threads, 1,571 registered users;
361 visitors (0 registered, 361 guests [including 24 identified bots]).
Forum time: 16:05 CEST (Europe/Vienna)

Don’t compromise yourself.
You are all you’ve got.    Janis Joplin

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