Globalizing Datetime Input RRS feed

  • Question

  • User946594116 posted

    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 <globalization culture="auto:en-US" uiCulture="auto"/>.

    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?

    Wednesday, May 3, 2006 1:33 PM

All replies

  • User1416329745 posted

    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.


    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>



    Thursday, May 4, 2006 9:00 AM
  • User-125436819 posted

    Hey Sheldon,

    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.


    Thursday, May 4, 2006 10:40 AM
  • User946594116 posted

    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.

    Thursday, May 4, 2006 11:43 AM
  • User946594116 posted

    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.


    Thursday, May 4, 2006 11:51 AM
  • User1416329745 posted

    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.



    Thursday, May 4, 2006 12:32 PM
  • User946594116 posted
    Thank you once again.  I have downloaded and printed the articles you recommend, and I will study them.  Hopefully, the solution to my problem is waiting there for me.
    Thursday, May 4, 2006 2:30 PM