date time format on localhost and iis server

FormView TextBox (insert mode) is bound with field in sql table like this:

Bind("Installed_Date", "{0:dd.MM.yyyy}")

Problem is when I enter date format like 30.01.2010 got error

String was not recognized as a valid DateTime.
Exception Details: System.FormatException: String was not recognized as a valid DateTime.

and data wont be inserted in table.
But if I enter 01.30.2010 insert is OK in ReadOnly mode date is 30.01.2010 and in sql table is the same date. Just to mention that text box in ReadOnly mode is bound same way Bind("Installed_Date", "{0:dd.MM.yyyy}").
How to enable insert with date entered in format and not with starting month?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can do it by changing the culture settings in web.config. Change the culture to "en-GB" in web.config.

For example,

        culture="en-GB"         uiCulture="en-GB" />

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Add asp:RegularExpressionValidator control to validate user's input for time.

<asp:RegularExpressionValidator runat="server" id="revDate" controltovalidate="txtDate" validationexpression="^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$" 
errormessage="Please enter date in dd.MM.yyyy format." />

Open in new window

Alternatively, you can try this code to accept date in dd.MM.yyyy format. Import using System.Globalization namespace in order to run this code.


     CultureInfo cultInfo = new CultureInfo("en-GB", true);
     DateTimeFormatInfo formatInfo = cultInfo.DateTimeFormat;
     formatInfo.ShortDatePattern = "dd.MM.yyyy";
     formatInfo.LongDatePattern = "dd MMMM yyyy";
     formatInfo.FullDateTimePattern = "dd MMMM yyyy HH:mm:ss";
     DateTime date1 = DateTime.Parse("30.01.2010", formatInfo);

Open in new window

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Just try this too

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Installed_Date","{0:dd/MM/yyyy}") %>'
kahvedzicAuthor Commented:

I just add this to web.config:

       uiCulture="en-GB" />

Now I can add when inserting new data to table, I can update and see as date format in FormView, but in my database I have mm/dd/yyyy and I also need to have same format ( in sql table. What to do?
The database will always have only one date format and it is normally based on local date time settings(regional settings) of the server/PC where the SQL server datase is running.  You don't need to worrky about the format in which the db is storing the data. You need to convert the date formate when you present the data to the user  through your UI application. You may be able to change the datetime format to 'dd/mm/yyy' format permanently by using the following sql server command.

set language 'british english'

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.