In a C# 2010 desktop application I am using a linq to sql statement to compare a C# datetime field to a sql server 2008 r2 datetime field. By doing this comparison I am getting inconsistent results. Thus I am guessing a C# datetime field is not the same as a sql server 2008 r2 datetime value.
Thus for this comparison to work, I would like to know how to change a C# datetime field to a sql server date time field. I would think I would need to do this conversion prior to comparing the dates.
I want to compare to see if sql date > minimum date (1/1/1753) and sql date < current today's date. Can you tell me how to write this comparision?
Thus now you show me code and/or point me to a reference that will show me how to solve this problem?
Loading

Sreejesh SPRank #1,975 · 740 reputationPosted Mar 4, 2013, 2:02 AM EST
sql date format is YYYY-MM-DD and c# date format is DD-MM-YYYY,
so pls change sql date or c# date format, my decision is pls change sql date format,
pls split sql date and change first and and third then compare ,
Thanks
Sreejesh
VulpesRank #55 · 29.2K reputationPosted Mar 4, 2013, 4:45 AM EST
So, if your C# DateTime is before midnight on 1/1/1753, this will set it to that minimum date.
There is no problem with the upper limits which are the same for both types.
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 4, 2013, 6:22 PM EST
Please refer below link it might help you.
http://weblogs.asp.net/zeeshanhirani/archive/2008/08/22/comparing-dates-in-linq-to-sql.aspx