Be careful when comparing DateTimes generated in C #. A DateTime struct in C # has higher precision than datetime 1 in SQL Server. Therefore, if you create a DateTime in C # (say from DateTime.Now), save it in the database and return it back, this will most likely be different.
For example, the following code:
using(SqlConnection conn = new SqlConnection("Data Source=.;Integrated Security=SSPI"))
using(SqlCommand cmd = new SqlCommand("SELECT @d", conn)){
DateTime now = DateTime.Now;
cmd.Parameters.Add(new SqlParameter("@d", now));
conn.Open();
DateTime then = (DateTime)cmd.ExecuteScalar();
Console.WriteLine(now.ToString("yyyy/MM/dd HH:mm:ss.fffffff"));
Console.WriteLine(then.ToString("yyyy/MM/dd HH:mm:ss.fffffff"));
Console.WriteLine(then - now);
}
returns the following example.
2009.06.20 12: 28: 23.6115968
2009.06.20 12: 28: 23.6100000
-00: 00: 00.0015968
, , epsilon:
Math.Abs((now - then).TotalMilliseconds) < 3
, , , , , .
:
1 . , " .000,.003 .007 "