Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the culture neutral dateformat for SQL Server

I have this question since the dawn of my programming career. Is there really a culture neutral format for datetime in sql server so that when ever I'm sending query string from a client side to the database server running sql server 2008 side having different system datetime format, and if the query contains a date converted to a string, what format would not give me an error.

like image 675
Soham Dasgupta Avatar asked Jan 11 '12 09:01

Soham Dasgupta


People also ask

What is SQL Server culture?

Culture: It is an optional parameter. By default, SQL Server uses the current session language for a default culture. We can provide a specific culture here, but the . Net framework should support it. We get an error message in case of invalid Culture.

What is the default date format in SQL Server?

The default string literal format, which is used for down-level clients, complies with the SQL standard form that is defined as YYYY-MM-DD. This format is the same as the ISO 8601 definition for DATE.

What is the format of timestamp in SQL?

SQL Date Data Types TIMESTAMP - format: YYYY-MM-DD HH:MI:SS.


1 Answers

I recommend reading Tibor Karaszi's The ultimate guide to the datetime datatypes.

If you input your date/time in unseparated or ISO 8601 format, then you should be fine with any configuration.

Unseparated = 'yyyymmdd hh:mm:ss'
ISO 8601    = 'yyyy-mm-ddThh:mm:ss'

Update (from comments):

If you need to enter a date only (without the time part), then you have to use the 'YYYYMMDD' format, as 'YYYY-MM-DD' will not work. See the linked article for an example.

like image 171
MicSim Avatar answered Sep 30 '22 23:09

MicSim