I am having problem saving date value in the database using EF.
In my C# code my dates are defined as:
DateTime ed = DateTime.Now.AddMonths(+6);
While in SQL Server the date
column is defined as DateTime
. Dates are sorted
in YYYY/MM/DD
format with no time.
When I try to insert values in the database with the following code:
t_a m = new t_a();
m.dbDate = DateTime.Today;
entity.AddTot_a(m);
entity.SaveChanges();
I get the following error message:
The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
I believe it is because the value is showing as MM/DD/YYY: HH:MM:SS
, while in the database it saves as YYY/DD/MM
. How can I solve this issue?