How to get the Regional Setting of ShortDate format 
Author Message
 How to get the Regional Setting of ShortDate format

I'm trying to get the Regional setting of shortdate format and ideally to
set to 'dd/mm/yyyy' if I can.

Have anyone tried this before?

Thanks in advance

--
Best Regards,

Billy Lau



Tue, 27 Feb 2001 03:00:00 GMT  
 How to get the Regional Setting of ShortDate format
Try this :

'
' Locale Constants
'
Public Const LOCALE_SDECIMAL = &HE
Public Const LOCALE_SLONGDATE = &H20
Public Const LOCALE_SSHORTDATE = &H1F
Public Const LOCALE_SCURRENCY = &H14
Public Const LOCALE_STHOUSAND = &HF
Public Const LOCALE_SINTLSYMBOL = &H15
Public Const LOCALE_STIMEFORMAT = &H1003

Public Const LOCALE_USER_DEFAULT As Long = &O0

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 Function GetDateFormat() As String
'
' This function will return the Locale date format for the system. Note that
the
' returned Year is always formatted to 'YYYY' regardless, to ensure
compliance with
' Y2k stuff.
'
    Dim lBuffLen As Long
    Dim sBuffer As String
    Dim lResult As Long
    Dim sDateFormat As String

    On Error GoTo vbErrorHandler

    lBuffLen = 128
    sBuffer = String$(lBuffLen, vbNullChar)

    lResult = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, sBuffer,
lBuffLen)

    If lResult > 0 Then
        sDateFormat = Left$(sBuffer, lResult - 1)
'
' Make sure we always have YYYY format for y2k
'
         If InStr(1, sDateFormat, "YYYY", vbTextCompare) = 0 Then
'
' Write your own replace string routine here
'
             'Replace sDateFormat, "YY", "YYYY"
         End If

         GetDateFormat = sDateFormat
    Else
        GetDateFormat = "DD/MM/YYYY"
    End If
    Exit Function

vbErrorHandler:
'
' Put your own error handling in here
'
End Function

Hope it helps

Chris Eastwood
Software Engineer
ACNielsen Ltd

Quote:

>I'm trying to get the Regional setting of shortdate format and ideally to
>set to 'dd/mm/yyyy' if I can.

>Have anyone tried this before?

>Thanks in advance

>--
>Best Regards,

>Billy Lau




Tue, 27 Feb 2001 03:00:00 GMT  
 How to get the Regional Setting of ShortDate format

Billy

Quote:
> I'm trying to get the Regional setting of shortdate format and ideally to
> set to 'dd/mm/yyyy' if I can.

> Have anyone tried this before?

Tried Format$(Date, "Short Date") ? In the IDE, "Short Date" is
the current user's setting (LOCAL_USER_DEFAULT), where when
Format is called from an executable, it's the system setting
(LOCALE_SYSTEM_DEFAULT, see the Format function example).
Or why not just simply do a Format$(Date, "'dd/mm/yyyy")...?


Tue, 27 Feb 2001 03:00:00 GMT  
 How to get the Regional Setting of ShortDate format
Hi Brad

 Weird huh ? I can't even remember where I found the definition for
LOCALE_USER_DEFAULT, but it works ok in the code.

 I've done a quick search of all my C/C++ header files and only found the
definition in OLENLS.H and WINNT.H

OLENLS.H
#define LOCALE_USER_DEFAULT    (MAKELCID(LANG_USER_DEFAULT))

WINNT.H

WINNT.H:#define LOCALE_USER_DEFAULT    (MAKELCID(LANG_USER_DEFAULT,
SORT_DEFAULT))

But where I got &HO0 from ?

Regards

Chris Eastwood
Software Engineer
ACNielsen Ltd

Quote:

>Hey Chris

>> ' Locale Constants
>> '
>> Public Const LOCALE_USER_DEFAULT As Long = &O0

>Darnedest thing, I just finished spending a good bit of time
>determining this constant's value, and came up different...
>I ended up getting...

>Public Const LOCALE_USER_DEFAULT = &H400
>Public Const LOCALE_SYSTEM_DEFAULT = &H800

>Attached is the whole macro route I went just to be sure.
>Checked out in C++ too...

>--
>Brad Martinez
>http://members.aol.com/btmtz/vb
>http://www.mvps.org/ccrp

>Please direct questions/replies to the newsgroup.



Tue, 27 Feb 2001 03:00:00 GMT  
 How to get the Regional Setting of ShortDate format
I think many VB programmer are facing the same problem.
The display of data control (textbox) is default to the short date setting
of the client machine.
That means we cannot know dd/mm/yyyy or mm/dd/yyyy unless we get the system
short date format.
otherwise, we can't check for a valid date cause some days such as
12/09/1998 and 09/12/1998 can be a valid
date depends on what the short date format.

Any suggestion on better solutions.

Billy lau

Quote:
>Tried Format$(Date, "Short Date") ? In the IDE, "Short Date" is
>the current user's setting (LOCAL_USER_DEFAULT), where when
>Format is called from an executable, it's the system setting
>(LOCALE_SYSTEM_DEFAULT, see the Format function example).
>Or why not just simply do a Format$(Date, "'dd/mm/yyyy")...?



Wed, 28 Feb 2001 03:00:00 GMT  
 How to get the Regional Setting of ShortDate format

Chris

Quote:
>  Weird huh ? I can't even remember where I found the definition for
> LOCALE_USER_DEFAULT, but it works ok in the code.

I'm not sure either, but there could be cases where it wouldn't...

Quote:
>  I've done a quick search of all my C/C++ header files and only found the
> definition in OLENLS.H and WINNT.H

> OLENLS.H
> #define LOCALE_USER_DEFAULT    (MAKELCID(LANG_USER_DEFAULT))

> WINNT.H

> WINNT.H:#define LOCALE_USER_DEFAULT    (MAKELCID(LANG_USER_DEFAULT,
> SORT_DEFAULT))

> But where I got &HO0 from ?

Those things sometime just go and appear on you. :-) Yeah, I pulled
the macros from Winnt.h... But since SORT_DEFAULT is defined as
0, both do the same thing...

--
Brad Martinez
http://members.aol.com/btmtz/vb
http://www.mvps.org/ccrp

Please direct questions/replies to the newsgroup.



Wed, 28 Feb 2001 03:00:00 GMT  
 How to get the Regional Setting of ShortDate format
LOCALE_USER_DEFAULT does not evaluate to a constant.  The simple way to
avoid this macro is to call GetUserDefaultLCID and pass its return value to
GetLocaleInfo as the locale ID.

--
     Jim Mack
     MicroDexterity, Inc
     PO Box 5372
     Plymouth, MI  48170-5372

     http://www.microdexterity.com



     Fax:  +1 734-453-8942

Quote:

>Chris

>>  Weird huh ? I can't even remember where I found the definition for
>> LOCALE_USER_DEFAULT, but it works ok in the code.

>I'm not sure either, but there could be cases where it wouldn't...

>>  I've done a quick search of all my C/C++ header files and only found the
>> definition in OLENLS.H and WINNT.H

>> OLENLS.H
>> #define LOCALE_USER_DEFAULT    (MAKELCID(LANG_USER_DEFAULT))

>> WINNT.H

>> WINNT.H:#define LOCALE_USER_DEFAULT    (MAKELCID(LANG_USER_DEFAULT,
>> SORT_DEFAULT))

>> But where I got &HO0 from ?

>Those things sometime just go and appear on you. :-) Yeah, I pulled
>the macros from Winnt.h... But since SORT_DEFAULT is defined as
>0, both do the same thing...

>--
>Brad Martinez
>http://members.aol.com/btmtz/vb
>http://www.mvps.org/ccrp

>Please direct questions/replies to the newsgroup.



Wed, 28 Feb 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Code to change Regional Shortdate setting

2. Code to change Regional Shortdate setting

3. Date format and regional settings

4. Number format and regional settings

5. Regional Settings problem with Val(), Format$(), etc...

6. Date format vbLongDate ignores server's regional settings

7. VBScript Date format- regional settings ?

8. reliable date formatting unrelated to regional settings

9. Getting regional settings

10. Formatting integers using regional settings

11. Getting the regional settings

12. How Can I Change the Short Date Format At Regional Settings in Control Panel

 

 
Powered by phpBB® Forum Software