by Taranjit Singh (1 Submission)
Category: Windows API Call/Explanation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 7th November 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Change Date Format of the system
API Declarations
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
'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