Hi guys,I found a post about this topic, but the solution was to write SQL code to that.I have c# datetime varialbes. When displayed, it's like: '12/12/09 11:04:32';Then, I create (by concatenation) a string which is my SQL query I need to Execute.But on inserting date, if format is like '12/12/09 11:04:32', there are problems (exception, or changed date.etc)SQL format is like '2009-12-12'.How can I change the Datetime format string in SQL 2008, using c# code?The user would chosoe the date from a DateTimePicker Control.Thx.Ashley Niekerk. The code is just:SqlConnection conn = new SqlConnection(connectionString);conn.Open;string s = 'SELECT email, passwd, loginid, fullname ' +'FROM members WHERE email = @email';SqlCommand cmd = new SqlCommand(s);cmd.Parameters.Add('@email', email);SqlDataReader reader = cmd.ExecuteReader;The key point is rather than writing a value inside the SQL statement (which needs to be formatted in a way understood by SQL Server regardless of the country, you use a @Placeholder.Then with Parameters.Add, you tell which native value (ie. If date it would be a date), you want to use for this placeholder. It will use a country neutral way to express this value so you won't ever had any conversion problem.Do you use SQL Server?Please always mark whatever response solved your issue so that the thread is properly marked as 'Answered'.
Standard Date and Time Format Strings. 28 minutes to read.In this articleA standard date and time format string uses a single format specifier to define the text representation of a date and time value. Any date and time format string that contains more than one character, including white space, is interpreted as a custom date and time format string; for more information, see.
A standard or custom format string can be used in two ways:.To define the string that results from a formatting operation.To define the text representation of a date and time value that can be converted to a or value by a parsing operation.
For DateTime values, this format specifier is designed to preserve date and time values along with the DateTime.Kind property in text. The formatted string can be parsed back by using the DateTime.Parse(String, IFormatProvider, DateTimeStyles) or DateTime.ParseExact method if the styles parameter is set to DateTimeStyles.RoundtripKind.