Compare DATETIME and DATE ignoring time portion(比较 DATETIME 和 DATE 忽略时间部分)
问题描述
我有两个表,其中 [date]
列是 DATETIME2(0)
的类型.
I have two tables where column [date]
is type of DATETIME2(0)
.
我只需要比较两条记录的日期部分(日+月+年),丢弃时间部分(小时+分钟+秒).
I have to compare two records only by theirs Date parts (day+month+year), discarding Time parts (hours+minutes+seconds).
我该怎么做?
推荐答案
对 SQL Server 2008 中新的 DATE
数据类型使用 CAST
以仅比较日期部分:
Use the CAST
to the new DATE
data type in SQL Server 2008 to compare just the date portion:
IF CAST(DateField1 AS DATE) = CAST(DateField2 AS DATE)
这篇关于比较 DATETIME 和 DATE 忽略时间部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!