Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
May 13, 2002



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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, _
sBuffer, lBufferLength)

        If lReturn > 0 Then
            GetDateFormat = Left$(sBuffer, lReturn - 1)
        End If
    End Function
Andreas Hillqvist
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date