Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Regional settings and date format problem

0 views
Skip to first unread message

Fred Flintstone

unread,
Aug 23, 2005, 4:25:13 PM8/23/05
to
I'm writing a VB.Net windows forms application. This line of code:

Personal.EffectiveDate = GridRow2.Cells("New
Value").Value.ToString.Trim

Fails with this error:

Cast from string "8/23/2005" to type 'Date' is not valid.

The date being returned is in US English and my system is set for
Canadian English. This is what I don't get. If my regional settings
are set for Canadian English, why is VB.Net returning US English
formatted dates?

? GridRow2.Cells("New Value").Value.ToString.Trim
Result: "8/23/2005"

? Personal.EffectiveDate
Result "#8/23/2005#"

Why? My system is set for Canadian English (dd/mm/yyyy), why is VB
returning US English dates (mm/dd/yyyy)? Someone suggested this:

Threading.Thread.CurrentThread.CurrentCulture = New
System.Globalization.CultureInfo("en-CA")
Threading.Thread.CurrentThread.CurrentUICulture = New
System.Globalization.CultureInfo("en-CA")

I put this in the Form_Load of my startup form. It makes no
difference. Then this was suggested:

Dim s As String = "8/25/2005"
Dim dt As Date = DateTime.Parse(s, New
System.Globalization.CultureInfo("en-US"))

That works. But I still don't get it. Above, we're parsing the date
assuming it's in US English. What if the system is set for UK
English? It'll return a UK date and crash with an invalid date error
again. Another problem is I can't do a "IsDate(MyDate) if the
regional settings are in conflict. Although the DateTime.Parse will
return a properly parsed date, the test for it will return false.

I don't understand:

- Why is VB returning US English dates when my regional settings are
set to CA English?
- How does an app like Excel or Outlook not crash at every turn if I
change the regional settings?

I'm confused, any advice appreciated.

Cor Ligthert [MVP]

unread,
Aug 24, 2005, 2:17:37 AM8/24/05
to
Fred,

Interesting.

AFAIK and from messages in this newsgroup is the Canadian English setting
MMddyyyy while the French Canadian setting is ddMMyyyy.

You are sure that it is in Canadian English the same as for French Canadian.

(Than those Enlish speaking Canadians would have used US settings)

However see this page.

http://publib.boulder.ibm.com/infocenter/db2help/index.jsp?topic=/com.ibm.db2.udb.doc/admin/r0004572.htm

Cor


Fred Flintstone

unread,
Aug 24, 2005, 8:24:45 AM8/24/05
to
My Regional Options are set to English (Canada). The short date
format is "24/08/2005". VB.Net is returnung dates the other way
around.

IMO, this is a massive bug or ignorant design. If my system is set to
dd/mm/yyyy, why, for any reason, would VB keep returning the dates in
US English? That makes absolutely no sense at all. I can't do date
conversions or comparisons if the date format being returned conflicts
with the format the system is set for. This is a financial
application, I can't just use US formats. And I can't convert them
because the system assumes it's a Cdn format.

I think MS needs to seriously rethink the regional settings, the
entire process is useless.

Thanks for the reply...

Cor Ligthert [MVP]

unread,
Aug 24, 2005, 9:43:19 AM8/24/05
to
Fred,

Does that mean that that IBM website from which I gave you the link is
wrong. It tells that the format in English Canada (0001) is MMddyyyy.

(For some EU European countries it is for sure given wrong (communist time
format) on this page).


Cor


Fred Flintstone

unread,
Aug 24, 2005, 11:26:57 AM8/24/05
to
Accoring to Windows, it's wrong. Screen grab is attached.

All development here has come to a screeching halt because of this.
We just don't know what to do because nothing is consistent. That IBM
page says the opposite of what MS says, VB.Net is returning dates in
formats that conflict with the regional settings.

We're completely screwed. Thanks Microsoft.

Cor Ligthert [MVP]

unread,
Aug 24, 2005, 11:53:27 AM8/24/05
to
Fred,

To test this I have set my system to English Canada and than this
Dim mydate As DateTime = CDate("24/8/2005")

No problem than I changed it to English US and got an error.

At least I learned something from it.

I hope however that my test and this sample helps something

Cor


Fred Flintstone

unread,
Aug 24, 2005, 12:37:59 PM8/24/05
to
I did post a reply to this with an image attached, I don't know why it
isn't showing up here. Yes, the IBM page is wrong, according to MS.

Y'know, I resigned to the fact that everything has to be done in US
dates and formats. So I went into my regional settings and set it all
back to US English and rebooted. Now this:

Public Function ConvertDate(ByVal MyDate As String) As Date
Return DateTime.Parse(MyDate, New
System.Globalization.CultureInfo("en-US"))
End Function

Is saying the same error. Why? Because the date being returned is:

"23/08/2005"

Regional settings says:

"8/24/2005"

I.... I can't win here. Pardon my impatience but what the HELL is
going on with this thing? If me regional says US, VB returns Canadian
dates. If I set it to Canadian, it returns US dates.

Has MS lost its collective mind?

Cor Ligthert [MVP]

unread,
Aug 24, 2005, 12:45:08 PM8/24/05
to
Fred,

Did you try my test.

By the way maybe are you telling us about the debugger/IDE

That is showing in every local settings only the US kind of dates.

Cor


0 new messages