
How to get the Regional Setting of ShortDate format
Try this :
'
' Locale Constants
'
Public Const LOCALE_SDECIMAL = &HE
Public Const LOCALE_SLONGDATE = &H20
Public Const LOCALE_SSHORTDATE = &H1F
Public Const LOCALE_SCURRENCY = &H14
Public Const LOCALE_STHOUSAND = &HF
Public Const LOCALE_SINTLSYMBOL = &H15
Public Const LOCALE_STIMEFORMAT = &H1003
Public Const LOCALE_USER_DEFAULT As Long = &O0
Public Declare Function GetLocaleInfo Lib "KERNEL32" _
Alias "GetLocaleInfoA" (ByVal lLocale As Long, _
ByVal lLocaleType As Long, ByVal sLCData As String, _
ByVal lBufferLength As Long) As Long
Public Function GetDateFormat() As String
'
' This function will return the Locale date format for the system. Note that
the
' returned Year is always formatted to 'YYYY' regardless, to ensure
compliance with
' Y2k stuff.
'
Dim lBuffLen As Long
Dim sBuffer As String
Dim lResult As Long
Dim sDateFormat As String
On Error GoTo vbErrorHandler
lBuffLen = 128
sBuffer = String$(lBuffLen, vbNullChar)
lResult = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, sBuffer,
lBuffLen)
If lResult > 0 Then
sDateFormat = Left$(sBuffer, lResult - 1)
'
' Make sure we always have YYYY format for y2k
'
If InStr(1, sDateFormat, "YYYY", vbTextCompare) = 0 Then
'
' Write your own replace string routine here
'
'Replace sDateFormat, "YY", "YYYY"
End If
GetDateFormat = sDateFormat
Else
GetDateFormat = "DD/MM/YYYY"
End If
Exit Function
vbErrorHandler:
'
' Put your own error handling in here
'
End Function
Hope it helps
Chris Eastwood
Software Engineer
ACNielsen Ltd
Quote:
>I'm trying to get the Regional setting of shortdate format and ideally to
>set to 'dd/mm/yyyy' if I can.
>Have anyone tried this before?
>Thanks in advance
>--
>Best Regards,
>Billy Lau