[英]Compare only DATE from 2 datetime columns - sql
How can I code to compare only the date (not time) from two different columns that is storing the date in 2015-01-10 01:20:00 format? 如何编码以2015年1月10日01:20:00格式存储日期的两个不同列中的仅日期(而非时间)进行比较? Example. 例。
Select * from Admissions
Where AdmitDateTime = DepartDateTime
Above will try to compare 2015-01-10 01:20:00 to 2015-01-10 01:20:00 instead of only date 2015-01-10 to 2015-01-10. 上面将尝试比较2015-01-10 01:20:00和2015-01-10 01:20:00,而不是仅将日期2015-01-10和2015-01-10进行比较。 Help Please. 请帮助。 Thanks. 谢谢。
Select * from Admissions
Where CAST(AdmitDateTime as date) = CAST(DepartDateTime as date)
You can convert or cast a DATETIME
data type to a DATE
data type. 您可以将DATETIME
数据类型转换或转换为DATE
数据类型。
For example: 例如:
SELECT *
FROM Admissions
WHERE
CONVERT(DATE, AdmitDateTime) = CONVERT(DATE, DepartDateTime)
Another way: 其他方式:
Select * from Admissions
Where DATEDIFF(dd,AdmitDateTime,DepartDateTime)=0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.