-
I have seen many posts on how to SET the date format from regional settings but none on how to just GET the date format. I don't want to change that date format because the users have other applications that are based on that setting. I just want to put in a label the format to use for entry (ex.: "dd-mm-yyyy" or "mm-dd-yyyy")
is this possible?
-
Sure thing!
Code:
Private 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
Private Const LOCALE_USER_DEFAULT = &H400
Private Const LOCALE_SSHORTDATE = &H1F ' short date format string
Private Const LOCALE_SLONGDATE = &H20 ' long date format string
Private Sub Form_Load()
Dim strLocale As String
Dim lngRet As Long
Dim strMsg As String
'Get short date format
strLocale = Space(255)
lngRet = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strLocale, Len(strLocale))
strLocale = Left(strLocale, lngRet - 1)
strMsg = "Short Date Format: " & strLocale
'Get long date format
strLocale = Space(255)
lngRet = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, strLocale, Len(strLocale))
strLocale = Left(strLocale, lngRet - 1)
strMsg = strMsg & vbCrLf & "Long Date Format: " & strLocale
MsgBox strMsg
End Sub
-
Right on!
Thanks a lot Serge!
I just love your direct and precise solutions