Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine a PCs current regional date setting

Status
Not open for further replies.

PreacherUK

Technical User
Joined
Sep 26, 2002
Messages
156
Location
NL
Chaps...and chapettes :)

We run some systems that require a person to switch their date settings from US to UK. However as is common with your average/garden user they can 'forget' to switch back to good old UK dates and times. Is there a way to detect what the current regional settings are? then the code can interpret the dates accordingly. I'd hesitate to automatically change the date settings on users PCs.

Cheers
 
Here is a function from VBNet that does just that.
Copy it all into a new module then look at the function ListDateFormats() which prints out the long & short date formats.

hth

Ben



Option Compare Database
Option Explicit

'--------------------------------------------------------------
' Copyright ©1996-2002 VBnet, Randy Birch, All Rights Reserved.
' Terms of use ' Modified slightly to run in Access & used instructions on
' VBNet to return current users settings rather than system
' default.
'--------------------------------------------------------------

Public Const DATE_LONGDATE As Long = &H2
Public Const DATE_SHORTDATE As Long = &H1
Public Const LOCALE_SLANGUAGE As Long = &H2 'localized name of language
Public Const LOCALE_SSHORTDATE As Long = &H1F 'short date format string
Public Const LOCALE_SLONGDATE As Long = &H20 'long date format string

Public Declare Function GetThreadLocale Lib "kernel32" () As Long

Public Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Public Declare Function GetUserDefaultLCID Lib "kernel32" () As Long

Public 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

Public Declare Function EnumDateFormats Lib "kernel32" _
Alias "EnumDateFormatsA" _
(ByVal lpDateFmtEnumProc As Long, _
ByVal Locale As Long, _
ByVal dwFlags As Long) As Long

Public Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)

Sub ListDateFormats()

Dim LCID As Long

'get the system's locale ID. Where the
'user's locale ID is required, call
'GetUserLocaleLCID instead.
LCID = GetUserDefaultLCID()

'show localized name of language
Debug.Print GetUserLocaleInfo(LCID, LOCALE_SLANGUAGE)

'Show the Long date format string for the LCID in use
Debug.Print "Long Date Format: " & GetUserLocaleInfo(LCID, LOCALE_SLONGDATE)

'Show the Short date format string for the LCID in use
Debug.Print "Short Date Format: " & GetUserLocaleInfo(LCID, LOCALE_SSHORTDATE)

End Sub

Public Function GetUserLocaleInfo(ByVal dwLocaleID As Long, _
ByVal dwLCType As Long) As String

Dim sReturn As String
Dim r As Long

'call the function passing the Locale type
'variable to retrieve the required size of
'the string buffer needed
r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))

'if successful..
If r Then

'pad the buffer with spaces
sReturn = Space$(r)

'and call again passing the buffer
r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))

'if successful (r > 0)
If r Then

'r holds the size of the string
'including the terminating null
GetUserLocaleInfo = Left$(sReturn, r - 1)

End If

End If

End Function





----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Yes, thats pretty much what I had managed to hunt up on the net. Its nice to know I was heading in the right direction and bumbled my way to the same end :)

Cheers for the confirmation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top