Change date format system


‘input your declaration

Public Const LOCALE_SSHORTDATE As Long = &H1F
Public Const LOCALE_USER_DEFAULT As Long = &H400

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 Declare Function SetLocaleInfo Lib “kernel32” _
Alias “SetLocaleInfoA” (ByVal Locale As Long, _
ByVal LCType As Long, ByVal lpLCData As String) As Long

‘input your code Form
‘put this code at form
‘i have used for short date format similarly it can be used for long
‘date format

Dim shortDateFormat As String
Dim lBuffSize As String
Dim sBuffer As String
Dim lRetGet As Long
Dim lRetSet As Long

lBuffSize = 256
sBuffer = String$(lBuffSize, vbNullChar)
‘get the date information in buffer
lRetGet = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, sBuffer, lBuffSize)

If lRetGet > 0 Then
shortDateFormat = Left$(sBuffer, lRetGet – 1)
‘this is the existing format of machine
End If
‘to change the format if doesn’t matches ur format
‘MM should be used in capital for monyhs,small m are for minutes
If LCase(shortDateFormat) <> “dd/mm/yyyy” Then
lRetSet = SetLocaleInfo(LOCALE_USER_DEFAULT,_ LOCALE_SSHORTDATE, “dd/MM/yyyy”)
‘on sucess lretset have value greater than 0
If lRetSet <= 0 Then
msgbox “date format not changed
End If
End If

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s