开发者

How to handle the discrepancy in precision between .NET CLR DateTime and datetime in SQL Server (and SQL CE)

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜