Datetime not equal

I have the following code:

DateTime endTime = DateTime.Now.AddDays(30); InsertIntoDatabase(endTime); var row = Db.SelectRow("select endTime from MyTable Where @column=myval", columnValue); Assert.Equal(row["endTime"], endTime); // This is false! Why? 

The statement is false. And dates for some reason are different milliseconds. Why???

= Final:

 Date {7/17/2015 12:00:00 AM} System.DateTime Day 17 int DayOfWeek Friday System.DayOfWeek DayOfYear 198 int Hour 1 int Kind Unspecified System.DateTimeKind Millisecond 370 int Minute 21 int Month 7 int Second 27 int Ticks 635726928873700000 long + TimeOfDay {01:21:27.3700000} System.TimeSpan Year 2015 int 

line ["EndTime"]:

 Date {7/17/2015 12:00:00 AM} System.DateTime Day 17 int DayOfWeek Friday System.DayOfWeek DayOfYear 198 int Hour 1 int Kind Local System.DateTimeKind Millisecond 371 int Minute 21 int Month 7 int Second 27 int Ticks 635726928873716049 long + TimeOfDay {01:21:27.3716049} System.TimeSpan Year 2015 int 

WHY???

+5
source share
2 answers

Maybe this (the difference between DateTime in C # and DateTime in SQL Server) will help a bit.

you can also use datetime2 for sql

+5
source

Looks like a rounding error for me, DateTime has ticks of 635726928873700000 , while Row has 635726928873716049 . This is likely due to different levels of accuracy in the database versus DateTime.

Tick โ€‹โ€‹differences mean they are different DateTimes.

0
source

All Articles