user's date format string

Y

YisMan

hi
is there any way with vba to return the string representing the *FORMAT*
that the user has set in regional settings for date display?
id appreciate any lead.
Thankfully, YisMan
 
D

Douglas J Steele

The following code (based on what Randy Birch has at
http://vbnet.mvps.org/code/locale/localeenumdates.htm) will give you the
user's Long Date or Short Date formats:

Public Const LOCALE_SSHORTDATE As Long = &H1F
Public Const LOCALE_SLONGDATE As Long = &H20

Public Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long

Public Declare Function GetLocaleInfo Lib "kernel32" _
Alias "GetLocaleInfoA" _
(ByVal Locale As Long, _
ByVal LCType As Long, _
ByVal lpLCData As String, _
ByVal cchData As Long) As Long


Public Function GetUserLocaleInfo(ByVal dwLocaleID As Long, _
ByVal dwLCType As Long) As String

Dim sReturn As String
Dim r As Long

' call the function passing the Locale type'variable to retrieve
' the required size of the string buffer needed
r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))

' if successful..
If r Then

' pad the buffer with spaces
sReturn = Space$(r)

' and call again passing the buffer
r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))

' if successful (r > 0)
If r Then

' r holds the size of the string 'including the terminating null

GetUserLocaleInfo = Left$(sReturn, r - 1)

End If

End If

End Function


Function GetLongDate() As String

Dim LCID As Long

LCID = GetSystemDefaultLCID()
GetLongDate = GetUserLocaleInfo(LCID, LOCALE_SLONGDATE)

End Function


Function GetShortDate() As String
Dim LCID As Long

LCID = GetSystemDefaultLCID()
GetShortDate = GetUserLocaleInfo(LCID, LOCALE_SSHORTDATE)
End Function


Easier might simply be to use DateSerial to generate a known date (say 02
January, 2003: DateSerial(2003, 2, 1)) and see what string is returned when
you reference it.
 
Top