I have a Db server with DateTime fields in the format of “yyyy-MM-dd mm:hh:ss”
I’m trying to use linq2sql to insert a DateTime member to a DateTime field in one of my tables.
When I do it in SQL I convert the DateTime as following:
“Insert into …. Convert(datetime, getdate(), 120) …”
But when I try to submit the object from Linq the date time inserts in the wrong format.
Is there a way to define the format that will be inserted to the Db in Linq?
Or is it a DateTime object Issue?
You shouldn’t be dealing with a string format when you pass dates and times to the database, any more than you would if you were passing a number. The database should be handling all this for you without any conversions. This is true whether you’re using LINQ or within the SQL – almost any time you have to manually do string conversions between types at the database level, you should look for a better solution.
If you read the value back out of the database (as a
DateTimeagain) does it have the right value? If not, in what way is it wrong?