Question Locked

Regional Date setting (Short Date)

0 helpful
18 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Does anyone know of a way to change the regional settings of a computer, but not have the change show in the control panel/regional settings?
We have a client that is somehow having such a problem, the regional settings in the control panel are correct, but the system is reading it from "someplace else" and using the wrong short date format.

It was in their login scripts, a reg file to correct the problem short date, but even that does not work, the file runs, the registry is correct, the GUI control panel shows correct, but the date format is still somehow wrong. (MM/dd/yyyy vs dd/MM/yyyy)

These are XP Pro machines

Any thoughts?

Edit
Solved (mostly). The VBScript changing the regional settings appears to be the culprit

18 replies

by seanferd

was the date format customized at the cpl? Was it perhaps customized in the local admin account and set to apply to the default profile as well, prior to setting up user accounts?

Only other things I can think of are: Group policy overriding the settings or another application which provides an interface to these settings.

by slayer_

So far, some research shows that the current user registry key was correct, an API call to grab the current setting worked, however, the application refused to read it correctly (Using MS OCX's such as date pickers). After I went into the regional settings manually, change them, then changed them back, suddenly everything started working. Is there maybe something else that needs to be set?

by john.a.wills

Or could it be just one application with the problem? Applications can overwrite the system settings - sometimes they are intended to.

by slayer_

Its a VBA application, most of the problems happens when converting strings to a date

example
?format(cdate("01/02/2010"),"MMMM d, yyyy")
Returns if set to Canadian
February 1, 2010
If set to American
January 2, 2010

Problem is in the registry, it is set to american, but when the code is run, it thinks it is Canadian.
As I said in the previous response, when I opened up the regional settings in the control panel, changed them, closed the panel, reopened it, changed them back, closed the panel, the code started working correctly.

by seanferd

which might change this. If everything appears to be set correctly, are you sure that the OCXs are a) getting their information from datime, and b) whatever call is being made with the OCX is structured (or whatever) properly to get the date in the desired format.

by tony hopkinson

then either it's being overridden in the code, or you've run into a bad bit of windows code or broken / unpatched windows install.
I've seen this a few times particularly with variants (directky or through ADO, some of the old code is hard coded to american as a default.
Given your response I suspect there's an override in application start up, your code or some MS drivel, given it squared it self up after you used control panel to toggle it, presumably while the app was running???

by slayer_

It looks like, the VBScript they were using to set the regional settings, were not working. I took an export of the International Key and imported it into a broken machine and it immediately started working. Running the exact same changes through VBScript breaks it again. Just importing the .reg file works fine. I told them to silently execute the reg file from their login script, hopefully that's what they will do. Worst case, they can just send the .reg file to each user with an email telling them to run it.

@Seanferd
LOL, can't its their missions critical program, without it, business closes.

by seanferd

"LOL, can't its their missions critical program, without it, business closes. "

I'm not exactly sure what you are referring to. I didn't suggest getting rid of the app (although at this point it sounds like it isn't written properly).

by tony hopkinson

And there's your problem,
it should be
format(cdate("2010-01-02"),"MMMM d, yyyy")
or
format(cdate("2010-02-01"),"MMMM d, yyyy")

Always use a universal format for dates input as strings.

by slayer_

I am just showing an example of how regional settings effect it.

And the "Real" problem is caused by code that is not ours.

by tony hopkinson

Explain why elbow dropping toilet bowls while crapping in the trousers is bad form.

by seanferd

LOL @ Sinister: I think Tony is suggesting that this other company needs to fix their code, and that if you aren't writing it, then they need to fix it themselves. Overall, I just don't think we are clear on who is working on what code, or how many apps are being referred to here - and (entertaining) confusion ensues!

LOL @ Tony: If you write code as well as you write quips, you're hired! I need to save that comment somewhere...

by slayer_

Its a multi national company, parts of the software are written by a rather lazy US team, and then forced onto the Canadian teams to use. Slowly though, the American teams are getting downsized until they are removed all together.
2 years ago we made a request for their special text box to expose the multi line property... still no response on that request. Should have been 10 minutes worth of work, tops. That's just one example.

by tony hopkinson

Sheesh I just found the reply button.
This sort of thing is all over the place, it's dead easy to introduce this sort of error. Look up most of tge examples to strng to sate and date to string and they never mention all the issues surrounding it.. You can get even more fun if you go work in say Holland where they use decimal point as thousand separators and comms as decimal points...
The trick is never make your program execution dependant on regional / cultural settings. It's a bit long winded at times but a few wrapper functions in a static class usually puts it to bed, and it's well worth the effort, because some twit of a user or a developer, will screw them up at some point leaving you looking like an eejit.

FxCop is big help on this in .net, becaseu it will point out all the places where you've been a twit. After a while you write globalised code out of self defence.

by slayer_

I am trying to write a function that will convert a string date to a universal date. Basically to take someones screwup and fix it. But I got stumped on short dates like "M/d/yyyy"
Primarily because the position of the "d" for example, won't necessarily be there if it is a 2 digit month or 2 digit day. I am probably taking the wrong approach to this, maybe I should figure out all the separators (anything not an M, d or y), store them, and then search for them in the result string, their everything that is not a separator should be the data I want. But that's a bit too complicated for me to wrap my head around to code.

This is what I got so far if you think you can help
[code]
Private Function GetUniversalDate(ByVal sDate As String) As String
Dim sDay As String
Dim sMonth As String
Dim sYear As String
Dim iDayLocation As Integer
Dim iDayCount As Integer
Dim iMonthLocation As Integer
Dim iMonthCount As Integer
Dim iYearLocation As Integer
Dim iYearCount As Integer
Dim sReturn As String
Dim sCount() As String 'the ubound is used to determine the number of entries

Dim strResult As String
Dim strInfo As String * 10
Dim lngIdentifier As Long
Dim lngResult As Long
lngIdentifier = GetUserDefaultLCID()
lngResult = GetLocaleInfo(lngIdentifier, LOCALE_SSHORTDATE, strInfo, 10)
strResult = Replace(strInfo, Chr(0), "")

'first, the days
sCount = Split(strResult, "d")
iDayCount = UBound(sCount)
iDayLocation = InStr(strResult, "d")

'now the months
sCount = Split(strResult, "M")
iMonthCount = UBound(sCount)
If iMonthCount > 3 Then
'THis will error, throw a message and break out returning the original data
sReturn = sDate
GetUniversalDate = sReturn
Call Oops("", 10, "Error, short date format cannot contain a full month (MMMM)", "GetUniversalDate")
Exit Function
End If
iMonthLocation = InStr(strResult, "M")

'And the years
sCount = Split(strResult, "y")
iYearCount = UBound(sCount)
iYearLocation = InStr(strResult, "y")
[b]
If iDayCount = 1 And iYearLocation > iDayLocation Then
iYearLocation = iYearLocation + 1
End If
[/b]

'So, using the locations and the count, we can get the values
sDay = Mid$(sDate, iDayLocation, [b]2[/b])
[b]
If IsNumeric(sDay) = False Then 'something wrong then
sDay = Mid$(sDate, iDayLocation, 1)
If iYearLocation > iDayLocation Then
iYearLocation = iYearLocation - 1
End If
End If
[/b]
sMonth = Mid$(sDate, iMonthLocation, iMonthCount)
sYear = Mid$(sDate, iYearLocation, iYearCount)

sReturn = sYear & "-" & sMonth & "-" & sDay
sReturn = Format$(CDate(sReturn), "yyyy/MM/dd")
GetUniversalDate = sReturn

End Function
[/code]
The bold code is the code I wrote to try and handle the problems I was having, so far no luck.

This discussion is closed to new replies.