0

I've been looking for a solution to this for hours. The problem I have having is that I have an SQL table which is storing dates as datetime DATATYPES, but when I try to pass a DateTime field to this table with Entity framework It's of datetime2 DATATYPE. All the solutions I found is using strings to format the date but this isn't working for me since I am using Entity Framework, and Entity Framework is expecting a DateTime type variable to be passed to the model and NOT a string.

result.SurveyDate = Convert.ToDateTime(CurrentSurveryDateValue);

I can't do something like the above because this is sending a datatime2 DATATYPE to the my model result. Which throws this error...

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value

Now I can't pass a string formatted to be of datetime format either because it throws a compile time error stating I can only pass DateTime types and not string...

How can i resolve this without changing the date datatype within my SQL table?

4
  • What is the exact value of CurrentSurveryDateValue? Convert.ToDateTime(CurrentSurveryDateValue)? Commented Sep 25, 2018 at 10:28
  • What is an example value that is causing an out-of-range error? Commented Sep 25, 2018 at 10:28
  • @mjwills The exact value im passing to CurrentSurveryDateValue is 13/10/2017 00:00:00 Commented Sep 25, 2018 at 11:05
  • @MarcGravell example value is 13/10/2017 00:00:00 which im using for all the dates. Commented Sep 25, 2018 at 11:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.