如何在T-SQL中测试两个datetimes相等(忽略它们的时间组件)? [英] How to test two datetimes for equality in T-SQL (ignoring their time components)?

查看:109
本文介绍了如何在T-SQL中测试两个datetimes相等(忽略它们的时间组件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何测试两个数据时间(不包括他们的时间组件)的平等?

How can I test two datetimes (not including their time components) for equality?

推荐答案

你最好的选择是使用 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.

这篇关于如何在T-SQL中测试两个datetimes相等(忽略它们的时间组件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆