Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to insert this datetime value to DB using EF 31/12/2021 11:59:59 PM (end of the day in the year)

1- i created this field fiscal_year_end and its datatype is DATETIME.
2- now i trying to update the record with the value fiscal_year_end
C#
var DB1 = ConnectionTools.OpenConn();
var SS = DB1.ad_system_settinges.Find(1);
SS.fiscal_year = NewYear;
SS.fiscal_year_start = NewYear_start;
SS.fiscal_year_end = NewYear_end;
DB1.SaveChanges();
where this variable NewYear_end have this value 31/12/2021 11:59:59 PM
but whene i checked the inserted value (using my project interface also also using workbench) i fount that this field fiscal_year_end have this value 2022-01-01 00:00:00 Which means it was rounded to the next day automatically (1 second was added).

What I have tried:

i putted break point after this line
C#
SS.fiscal_year_end = NewYear_end;
and i fount that have this value 31/12/2021 11:59:59 PM
Posted
Updated 9-May-20 11:35am
v3
Comments
MadMyche 9-May-20 17:17pm    
Which value is that; ss.fiscal_year_end or NewYear_end?
What happens if you step to the next line; is the value the same?
Golden Basim 9-May-20 17:35pm    
i putted break point after this line
 SS.fiscal_year_end = NewYear_end;
and i fount that the both ss.fiscal_year_end or NewYear_end have this value 31/12/2021 11:59:59 PM
Richard MacCutchan 10-May-20 4:02am    
Why do you need both times? If you just set year start to the first day at 00:00:00, it is a simple matter to calculate the end date.
Golden Basim 11-May-20 11:21am    
Yes, your words are logical, I will actually do it, but I would also like to know the reason why the value is inserted wrongly in databases
Richard MacCutchan 11-May-20 12:04pm    
We cannot tell you why it is wrong as we have no access to either your code or your data. You need to use your debugger to see exactly what happens when you run the above code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900