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!
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!