In .NET the DateTime data type is precision to 100ns. In SQL Server and SQL CE the datetime type is not that precise .
I have tons of code that uses DateTime.Now or DateTime.UtcNow. The values returned from those calls are then stored in the database. Depending on the value, when I pull that data out of the database, it will not match the entered value. As a result unit tests fail and business logic that relies on the comparisson fails
This has to be a very common problem. Do I have to go everywhere in my code where I 开发者_运维百科see DateTime.UtcNow or DateTime.Now and round it down? If I do that, I would also have to prevent all future references to DateTime.Now and DateTime.UtcNow. Is there a way to easily prevent that?
Are there other standard approaches?
Thanks
精彩评论