Change Date System

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

‘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
‘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: Logo

You are commenting using your 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