473,569 Members | 2,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regional settings and date format problem

I'm writing a VB.Net windows forms application. This line of code:

Personal.Effect iveDate = GridRow2.Cells( "New
Value").Value.T oString.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.T oString.Trim
Result: "8/23/2005"

? Personal.Effect iveDate
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.Threa d.CurrentThread .CurrentCulture = New
System.Globaliz ation.CultureIn fo("en-CA")
Threading.Threa d.CurrentThread .CurrentUICultu re = New
System.Globaliz ation.CultureIn fo("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.Globaliz ation.CultureIn fo("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(MyD ate) 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
7 12619
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
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
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
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
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
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(ByV al MyDate As String) As Date
Return DateTime.Parse( MyDate, New
System.Globaliz ation.CultureIn fo("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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2239
by: Ishbel Kargar | last post by:
Since upgrading from old laptop (Windows 98) to new laptop (Windows XP), my mail-merge letters are doing strange things with date formats. For instance, my reminder letter for lapsed subs carries the 'expiry' date as a merge field from the database, and this previously was shown as dd/mm/yy (UK format). Now it persists in showing as...
2
4541
by: Bob Dydd | last post by:
Hi Everbody Question Changing the regional settings ie. from UK to US AUS etc, Access retains the original currency format that the application was created in. So if an mdb that is written on a computer with Regional Settings Currency Format set to UK £'s , when that mdb is open on a machine
5
8232
by: Daveo | last post by:
Hi there, I'm having a problem with my database changing the date that I enter in the format dd/mm/yyyy into American format. Bizarrely, when enter the date in a textbox it changes round, but if I change the format of the textbox from short date to medium or long date, the date appears as it is supposed to. I also have a calendar control...
3
3586
by: opticstorm | last post by:
i want to know is that is it possible to get a web clients date format i.e. like (DD/MM/YY) or (YYYY/MM/DD) from asp.net. or any other client scripting languages like jscript,javascript. no perl please. if so then how. please reply
1
1709
by: zsolt | last post by:
Hi, I'm trying to convert a string to date by specifying the format. The value is like this: "03rd of April 2006". Now this is converted fine by using the following format: "dd\r\d \o\f MMMM yyyy". The problem is of course that the string can be 01st of..., 04th of etc., meaning that I can't use the "\r\d" format description for all...
7
4271
by: mewanalwis | last post by:
Dear Friends, I have a rather strange problem which invloves SQL server and ASP. The problem is this. I have an ASP application which use a SQL server. it saves date values with MM/dd/yyyy format. the SQL server and every other computer is configured to MM/dd/yyyy format in reginol settings. The DSN which use to connect to SQL server...
1
1632
by: cableguy69 | last post by:
Hello There. I am programming with visual basic within the Excel realm. I have a problem with the way my selected textbox recognizes dates generated from the datepicker. I am from New Zealand and have set me PC regional settings accordingly. Our date format is 26 October 2006, 26/10/06. I have formatted the textbox with the following...
16
11879
by: Mik | last post by:
I apologise if this post seems a little basic, but I am a newbie and have NO access knowledge. I have downloaded the Accounts Ledger from the Microsoft Website. It allows the user to review a report of transactions between a Start & End date. The Tables and forms i believe are UK format "dd/mm/yyyy", However, when I click on "Review...
1
4034
by: Maciej07 | last post by:
Hello, We are using SQL server 2000 on W2k Server and MS Access 2000 ADP (like front-end). Now we try to change operating system for SQL Server 2000 from W2k to W2k3 and we found problem with date format - we receive error: "Cannot convert date type varchar to datetime". Datetime used in application are sent to SQL Server 2000 in format...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.