How can I test two datetimes (not including their time components) for equality?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Your best bet would be to use DATEDIFF
For example to only compare the months:
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.
回答2:
DATEDIFF(day, rem.DueDate , GETDATE()) = 0
回答3:
To test if the two dates are equal, ignoring the time component:
SELECT DATEDIFF(day, @first, @second) = 0
To test if the two times are equal, ignoring the date component:
SELECT DATEADD(day, -DATEDIFF(day, 0, @first), @first) =
DATEADD(day, -DATEDIFF(day, 0, @second), @second)
回答4:
This should work:
SELECT * FROM MyTable
WHERE floor(convert(real,date1))=floor(convert(real,date2))