I have a TextBox server control on a Web Form, say, txtDueDate. I don’t want to use DateTimePicker but want to use TextBox itself. The user enters date in dd/mm/yyyy format.
While passing this value to SQL Server 2005 (Express) stored procedure, I use something like:
cmdParameters.AddWithValue("@DueDate", Convert.ToDateTime(txtDueDate.Text));
The stored procedure has input parameter to handle this value and is declared as:
@DueDate SmallDateTime
I want to know the default format SQL Server 2005 uses internally to store this date. On my PC, the Windows XP Regional Settings are set to dd/mm/yyyy format. While viewing records through Management Studio, it is stored correctly. But I am worried about users who will be using this web application. The Windows Regional Settings may differ on their PC.
I want to be sure whoever queries the database, the date is displayed in dd/mm/yyyy format. If someone inserts, 02/01/2004, then it should not become a valid reverse date like: 01/02/2004.
A
DateTimeis aDateTimeis aDateTime– it doesn’t “have” any (string-oriented) format when stored in SQL Server (it’s stored as a 64-bit long). If you pass in a parameter to a stored procedure as aDateTimealready, you should be just fine! The value will be stored by SQL Server without changing any formatting – since it doesn’t have any formatting associated with it…The only point the date is represented in a given string format is when you look at it in SQL Server Management Studio, or when you convert it to a string format in e.g. your .NET app.
When you need to somehow pass in a string-representation into SQL Server (e.g. for searching etc.), the one that’s the most robust and will work with any regional/language setting is the ISO-8601 date format:
YYYYMMDDor alternatively (if you need the time portion)YYYY-MM-DDTHH:MM:SS(where theTin the middle is a literal, separating the date and time portions)