devxlogo

Get Date Format String

Get Date Format String

There is no native function for returning the current date format string. Here’s a simple function that calls the GetLocaleInfo API in order to retrieve the short date format string:

     Private Const LOCALE_SSHORTDATE = &H1F    Private Const LOCALE_USER_DEFAULT As Long = &H400    Private 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 Function GetDateFormat() As String    Dim lReturn As Long    Dim sBuffer As String    Dim lBufferLength As Long        lBufferLength = 128        sBuffer = String$(lBufferLength, 0)        lReturn = GetLocaleInfo(LOCALE_USER_DEFAULT, _LOCALE_SSHORTDATE, sBuffer, lBufferLength)        If lReturn > 0 Then            GetDateFormat = Left$(sBuffer, lReturn - 1)        End If    End Function

devx-admin

Share the Post: