dynamicuser dynamicuser - 10 months ago 54
C# Question

Change the date format in SQL Server 2012

I have a SQL Server 2012 Express database that has been installed on a server in Germany. I created a database and have now realised the date formats are incorrect. I need to show each date as dd/mm/yyyy.

When I run dbcc useroptions (after making some changes to the server), I get the following -

language dateformat
British dmy

When I run
select GetDate()
in a new query, it shows the date as follows -

2014-08-28 13:53:10.550

The bottom line issue is when I enter
in to a textbox on a web forms project, it errors

String was not recognized as a valid DateTime.

selP.StartDate = Convert.ToDateTime(tbStartDate.Text);

Any ideas why this is happening? I have created a new user since changing the settings to British and dmy, which still produces the same error.

Answer Source

The proper way to achieve that is to set the culture of your web application.

How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization