Friday, December 26, 2008

Get System Date Format

VB Version: 6

This code will demontrate how to retrieve system date format refer to regional setting of windows.

Retrieving system date format will be usefull to avoid error or mistake while converting/formating date based on system date format setting.

Code:

Private Declare Function GetProfileString _
Lib "kernel32" _
Alias "GetProfileStringA" _
(ByVal lpAppName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long) As Long

Private Sub Form_Load()

Dim lngReturn As Long
Dim strDateFormat As String
Dim strDateSeparator As String

strDateFormat = String$(25, 0)
lngReturn = GetProfileString("Intl", "sShortDate", "", strDateFormat, Len(strDateFormat))
strDateFormat = Left$(strDateFormat, lngReturn)

strDateSeparator = String$(5, 0)
lngReturn = GetProfileString("Intl", "sDate", "", strDateSeparator, Len(strDateSeparator))
strDateSeparator = Left$(strDateSeparator, lngReturn)

MsgBox "System date format is " & strDateFormat & _
vbCrLf & _
"System date separator is " & strDateSeparator

End Sub


No comments:

Post a Comment