By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Regional settings and date format problem

P: n/a
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.

Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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/infoce...n/r0004572.htm

Cor
Nov 21 '05 #2

P: n/a
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...
On Wed, 24 Aug 2005 08:17:37 +0200, "Cor Ligthert [MVP]"
<no************@planet.nl> wrote:
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/infoce...n/r0004572.htm

Cor


Nov 21 '05 #3

P: n/a
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
Nov 21 '05 #4

P: n/a
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.
On Wed, 24 Aug 2005 15:43:19 +0200, "Cor Ligthert [MVP]"
<no************@planet.nl> wrote:
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


Nov 21 '05 #5

P: n/a
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


Nov 21 '05 #6

P: n/a
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?

On Wed, 24 Aug 2005 15:43:19 +0200, "Cor Ligthert [MVP]"
<no************@planet.nl> wrote:
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


Nov 21 '05 #7

P: n/a
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
Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.