且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在T-SQL中测试两个datetimes相等(忽略它们的时间组件)?

更新时间:1970-01-01 07:55:48

你***的选择是使用 DATEDIFF

例如,只比较几个月:


SELECT DATEDIFF(month,'2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000');

SELECT DATEDIFF(month, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000');

这是比较的***方法,并根据您对查询的确切需求来确定差异。甚至下降到毫秒。

This is the best way to do comparisons and determine the differences based on your exact need for the query your doing. It even goes down to milisecond.