Long and Short Month Names in current Locale [for WINDOWS].

It appears user settings apply only to the system default language. I set date formats to use numeric instead of text month, and indeed, en-EN or en-US on my English system do show numeric months.

But the snippet I posted with a French locale do show “août” even if the user has selected numeric values for months.

Sure, it does not solve the issue for the default language, but Xojo.Core.Date does provide the month name for all others languages.

[quote=327420:@Norman Palardy]Will confess I did not read the whole thread
On Windows there are definitely Calendar related functions (https://msdn.microsoft.com/en-us/library/windows/desktop/dd318075(v=vs.85).aspx)
And using the right parameter for the Calendar Info Type you can get the names of weekdays and months
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317734(v=vs.85).aspx

And FWIW at on time Aarons WFS had a VB function for exactly this
You might look there first[/quote]

THANK YOU NORMAN…

https://forum.xojo.com/10598-windows-functionality-suite-url

for those of you following this … .here is a CROSS platform method to get the name of the month is both SHORT and LONG formats localized to the users language as set in SysPref, but NOT dependant on any system level Date formats they may have set.

The WINDOWS code was modified from code I found in Aaron Ballmans WFS package. So it might be made more compact, but this seems to work…

Private Function getMonthName(mth as integer,asShortName as boolean=false,forceEnglish as boolean=false) as string
  If mth<1 Or mth>12 Then Return ""
  If forceEnglish Then 
    Return getMonthNameENGLISH(mth,asShortName)
  End If
  //
  #If TargetMacOS Then 
    Declare Function NSClassFromString Lib "Foundation" (className As CFStringRef) As Ptr
    Declare Function alloc Lib "Foundation" Selector "alloc" (NSClass As Ptr) As Ptr
    Declare Function init Lib "Foundation" Selector "init" (NSObject As Ptr) As Ptr
    Declare Function objectAtIndex Lib "Foundation" Selector "objectAtIndex:" (NSArray As Ptr, idx As UInt32) As CFStringRef
    Declare Function monthSymbols Lib "Foundation" Selector "monthSymbols" (NSDateFormatter As Ptr) As Ptr
    Declare Function shortMonthSymbols Lib "Foundation" Selector "shortMonthSymbols" (NSDateFormatter As Ptr) As Ptr
    Dim dateFormatter As Ptr = init(alloc(NSClassFromString("NSDateFormatter")))
    If asShortName Then 
      Return objectAtIndex(shortMonthSymbols(dateFormatter), mth-1)
    Else
      Return objectAtIndex(monthSymbols(dateFormatter), mth-1)
    End If
  #EndIf
  //
  // For now Windows only returns English Locale
  #If TargetWindows Then 
    Dim mb As New MemoryBlock( 2048 )
    Dim ret As Integer
    Dim retVal As String
    Dim mthIndex As Integer
    Dim returnValue As Integer
    Dim size As Integer
    
    Const LOCALE_USER_DEFAULT = &H400
    Soft Declare Function GetLocaleInfoA Lib "kernel32" (Locale As Integer, LCType As Integer, lpLCData As ptr, cchData As Integer) As Integer
    Soft Declare Function GetLocaleInfoW Lib "kernel32" (Locale As Integer, LCType As Integer, lpLCData As ptr, cchData As Integer) As Integer
    //
    If asShortName Then 
       mthIndex = 56'&h00000038
    Else
       mthIndex = 68'&h00000044
    End If
    mthIndex=mthIndex+(mth-1)
    
    //
    If mb <> Nil Then size = mb.Size
    
    If System.IsFunctionAvailable( "GetLocaleInfoW", "Kernel32" ) Then
      If mb <> Nil Then
        returnValue = GetLocaleInfoW(LOCALE_USER_DEFAULT, mthIndex, mb, size ) * 2
        retVal = ReplaceAll( DefineEncoding( mb.StringValue( 0, returnValue ), Encodings.UTF16 ), Chr(0), "" )
      Else
        returnValue = GetLocaleInfoW(LOCALE_USER_DEFAULT, mthIndex, Nil, size ) * 2
      End If
    Else
      If mb <> Nil Then
        returnValue = GetLocaleInfoA(LOCALE_USER_DEFAULT, mthIndex, mb, size ) * 2
        retVal = ReplaceAll( DefineEncoding( mb.StringValue( 0, returnValue ), Encodings.ASCII ), Chr(0), "" )
      Else
        returnValue = GetLocaleInfoA(LOCALE_USER_DEFAULT, mthIndex, Nil, size ) * 2
      End If
    End If
    
    Return retVal 
  #EndIf
End Function