Last post May 04, 2006 02:30 PM by Sheldon
May 03, 2006 01:33 PM|Sheldon|LINK
I am working on an application that has a number of textboxes where the user must input a date. In my web.config file, I have
One page has a textbox that opens with a default value of today's date, 4/28/2006 in U.S. format. If I go to the IE Tools menu and change the Language setting to Thai, the date in that textbox changes,
as expected, to the Thai equivalent, 28/4/2549.
So far, so good. But if I then attempt to save the data, I get an Invalid Date error because my SQL Server, which is in the US, does not understand '28/4/2549' as a date.
Do the Culture and UICulture settings affect output only, or is there some way I can get it to translate the Thai format to US format before returning it to the server?
May 04, 2006 09:00 AM|Caddre|LINK
The way you fix that is to create your database with Thai collation and also use Thai collation in your create table statement. So your database may be in the US but it is expecting Thai data and date. Try the links below read up on SQL Server collation
and code page. Post again if you still need help. Hope this helps.
May 04, 2006 10:40 AM|owingruters|LINK
I recon you should do this the other way around.
Always set your database dates in InvariantCulture style and have the display controls make you the right culturespecific format.
May 04, 2006 11:43 AM|Sheldon|LINK
Thank you for your reply. I failed to state in my original question that this application will be used in the U.S., Thailand and possibly other countries. What I actually need is for any dates entered by users, regardless of the location of the user, to
be converted to U.S. format before submission back to the server.
The <globalization> tag in web.config is supposed to handle this situation, and in fact, it does so effectively as far as output is concerned. But I have been unable to get it to work with input.
May 04, 2006 11:51 AM|Sheldon|LINK
Thank you for your reply, Owin.
Can you explain your suggestion a bit? How do I set the database dates in InvariantCulture style? I'm afraid I don't know what that means. Of course, I want dates to display in the user's native format and be converted to U.S. format only upon submission.
May 04, 2006 12:32 PM|Caddre|LINK
Check CultureInfo.InvariantCulture property in System.Globalization in the first link and the second link shows how to create culture neutral datetime in SQL Server. Hope this helps.
May 04, 2006 02:30 PM|Sheldon|LINK