How to change the date format in the regional settings to dd/mm/yyyy as and when my application(in vb) loads?
Printable View
How to change the date format in the regional settings to dd/mm/yyyy as and when my application(in vb) loads?
Private Const LOCALE_SLONGDATE As Long = &H20 'long date format string
Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
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 Sub Command1_Click()
MsgBox GetLongDateFormat
End Sub
Private Function GetLongDateFormat() As String
Dim LCID As Long
'get the locale for the user
LCID = GetSystemDefaultLCID()
If LCID <> 0 Then
'return the long date format
GetLongDateFormat = GetUserLocaleInfo(LCID, LOCALE_SLONGDATE)
End If
End Function
Private 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 r 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
Iouri Boutchkine
[email protected]