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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ideal Method for Handling Diverse Localization Settings

Status
Not open for further replies.

Phylum

IS-IT--Management
Aug 16, 2004
36
0
0
US
A few years ago when I started in my current position I got bit by the regional settings bug: I was coding for MM/DD/YYYY format but our friends in the UK and Brussels were using DD/MM/YYYY format. I found my mistake and corrected it, yay..., so now it looks like this:

If (Now() > DeployDate("8/11/2011","")) Then
pushsoftware
end if

Function DeployDate(StartDate,StartTime)
targetDate = Split(targetDate,"/")
Select Case Office
Case "UK","BR"
' This is DD/MM/YYYY format
SerializedDate = DateSerial(targetDate(2),targetDate(1),targetDate(0))
Case Else
' This is MM/DD/YYYY format
SerializedDate = DateSerial(targetDate(2),targetDate(0),targetDate(1))
...
Then we handle StartTime & serialize it
...
DeployDate = SerializedDate
End Function

So far, this seems to work fine. But then I realized I was making an awful lot of assumptions, specifically that our UK & Brussels users were *not* using the US regional settings. I dislike hard coding for a specific format that could easily vary.
If a UK user changes the date format to MM/DD/YYYY, although they're the minority, the function is now broken for them and what should be August 11th 2011 is now November 8th 2011. (The same could be set for a US user changing their regional settings and now they would be 'broken'.)

Is there a safe method for dealing with different regional settings so that I can use "8/11/2011" (August 11th) as an install push date and it properly get converted (like 11/8/2011 for European date formats etc) no matter what the local system's regional settings are?

I figure I might have to use the GetLocale and SetLocale but I'm not sure, mainly due to lack of experience using them. But I was hoping to avoid doing something like this at the beginning and end of the login script.

If (GetLocale() <> "1033") Then
origlocale = GetLocale
SetLocale(1033)
End if
...
the rest of the script.
...
If Not (IsEmpty(origlocale)) Then
SetLocale(origlocale)
End if


Any advice is greatly appreciated!
 
The safer way I know is to use a non ambiguous format, ie "2011-08-11" instead of "8/11/2011".

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
And that format works everywhere, no matter the format of the local machine running the script?

Thanks for this information!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top