How to insert c# DateTime?

  • Thread starter Thread starter me
  • Start date Start date
M

me

Is there some way to insert a c# datetime in a table
without dealing with culture? The datetime object
probably has som internal representation thats
culture independant and the database probably stores
datetime internally as a long. If i try to insert like
this:

insert into x(somedatefield) values ('datestring')

then i have to format the datetime object in some
culture specific string and make sure the database
uses the same format. Is there some way to insert
a date without dealing with culture settings on
client and db server?
 
me said:
Is there some way to insert a c# datetime in a table
without dealing with culture? The datetime object
probably has som internal representation thats
culture independant and the database probably stores
datetime internally as a long. If i try to insert like
this:

insert into x(somedatefield) values ('datestring')

then i have to format the datetime object in some
culture specific string and make sure the database
uses the same format. Is there some way to insert
a date without dealing with culture settings on
client and db server?

Apart from Miha's solution with parameters, you should
consider that the format in the SQL statement is NOT culture
specific. Even if the database program shows the data in a
culture specific way, you shouldn't use this format when
using SQL.

In SQL, it is always the American mm-dd-yyyy format.
 
Apart from Miha's solution with parameters, you should
consider that the format in the SQL statement is NOT culture
specific. Even if the database program shows the data in a
culture specific way, you shouldn't use this format when
using SQL.

In SQL, it is always the American mm-dd-yyyy format.

dosent work here. I have to use yyyy-mm-dd.

i know sql server has a "set" instruction to set the
format explicitly.
 
Back
Top