I have a column with the date type in my SQL database. How can I convert it to C# DateTime and then back again to a SQL date?
date
DateTime
A sql DATE can be directly cast to a .net DateTime and vice-versa.
DATE
to get it, use the SqlDataReader.GetDatetime Method
DateTime myDate = myDataReader.GetDateTime(myColumnIndex);
to set it, simply assign it to the value of the SqlParameter and use the .Date property of the DateTime
.Date
2.1m questions
2.1m answers
60 comments
57.0k users