Results 1 to 3 of 3

Thread: How to GET the system date format from regional settings

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241
    I have seen many posts on how to SET the date format from regional settings but none on how to just GET the date format. I don't want to change that date format because the users have other applications that are based on that setting. I just want to put in a label the format to use for entry (ex.: "dd-mm-yyyy" or "mm-dd-yyyy")

    is this possible?

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Sure thing!
    Code:
    Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long
    Private Const LOCALE_USER_DEFAULT = &H400
    Private Const LOCALE_SSHORTDATE = &H1F ' short date format string
    Private Const LOCALE_SLONGDATE = &H20 ' long date format string
    
    
    Private Sub Form_Load()
        Dim strLocale As String
        Dim lngRet As Long
        Dim strMsg As String
        
        'Get short date format
        strLocale = Space(255)
        lngRet = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strLocale, Len(strLocale))
        strLocale = Left(strLocale, lngRet - 1)
        
        strMsg = "Short Date Format: " & strLocale
        
        'Get long date format
        strLocale = Space(255)
        lngRet = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, strLocale, Len(strLocale))
        strLocale = Left(strLocale, lngRet - 1)
        
        strMsg = strMsg & vbCrLf & "Long Date Format: " & strLocale
        
        MsgBox strMsg
    End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Thumbs up Right on!

    Thanks a lot Serge!

    I just love your direct and precise solutions

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width