Reputation: 2207
I have started to use entity framework and after doing research i have found that Entity Framework only accepts the DateTime format DateTime2.
What is the best way to convert a DateTime picker to the format of Datetime2
I currently do the following
string strCastFrom = this.dtCastFrom.Value.Year.ToString("0000") + "-" + this.dtCastFrom.Value.Month.ToString("00") + "-" + this.dtCastFrom.Value.Day.ToString("00") + "T00:00:00";
Is therea better way to convert datetime to DateTime2?
Upvotes: 1
Views: 2075
Reputation: 1502536
Don't perform any string conversions. Just use
DateTime value = dtCastFrom.Value;
Let the Entity Framework itself take care of getting the data to the database. You don't want a string representation, and there's no reason to go via a string representation. This isn't just the case for EF, it's a general principle.
Upvotes: 4