DateTime -- Comparisons

Posts   
 
    
caseyry
User
Posts: 79
Joined: 25-Feb-2005
# Posted on: 28-Mar-2006 23:23:30   

Hi --

I'm running version 1.2005.1 Final (October 23, 2005).

Maybe I'm missing something here, but date comparisons are driving me a little crazy.

In the NUnit test below, two dates that before they are saved to the db (SQL Server 2000) are "Equal." After the Entity is saved to the database, they are no longer equal. The NUnit test fails on the last assert. (The date field is stored as a DateTime in SQL Server.)


[NUnit.Framework.Test()]
public void DateTest ()
{
    DateTime t1 = DateTime.Now;
    DateTime t2 = t1;

    HtmlStyleSheetEntity entity = new HtmlStyleSheetEntity();
    entity.Active = true;
    entity.CreateUserId = 2;
    entity.CreateDate = t1;

    Assert.AreEqual(t1, t2);

    Assert.AreEqual(t1, entity.CreateDate, "before save");

    entity.Save();
    Assert.AreEqual(t1, entity.CreateDate, "entity failed after saved");

}

Results: DateTest : entity failed after saved expected:<3/28/2006 4:19:32 PM>

but was:<3/28/2006 4:19:32 PM>

Is this a known issue or am I missing something? If I change the test to:


Assert.AreEqual(t1.ToString(), entity.CreateDate.ToString(), "entity failed after saved");

It passes.

Thanks.

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 28-Mar-2006 23:55:08   

Time in SQL Server has a resolution of 3.33 milliseconds.

Since the value is refetched, it will no longer match since DateTime resolution in Dotnet is higher.

http://vyaskn.tripod.com/searching_date_time_values.htm

http://www.sommarskog.se/arrays-in-sql.html

caseyry
User
Posts: 79
Joined: 25-Feb-2005
# Posted on: 29-Mar-2006 00:14:32   

JimHugh wrote:

Time in SQL Server has a resolution of 3.33 milliseconds.

Ah, thanks!