簡體   English   中英

SQL:如何在忽略時間的情況下比較日期?

[英]SQL: How to compare dates while ignoring the time?

如何比較時間戳的日期而忽略時間?

我只想比較月/日/年。 例如:

select * from Batch
where openingtime <> closingtime

問題是這將顯示太多批次,因為它將包括OpeningTimeClosingTime僅在一天中的時間不同的批次:


OpeningTime = 2010-07-07 11:19:29.000


ClosingTime = 2010-07-07 19:19:22.000

將兩個時間戳都作為日期

對於SQL Server

Select * 
from Batch 
where cast(openingtime as date) <> cast(closingtime as date)

對於Oracle

Select * 
from Batch 
where trunc(openingtime) <> trunc(closingtime)

其他方式

Select * from Batch where      
CONVERT(VARCHAR(10),openingtime,110<>CONVERT(VARCHAR(10),closingtime,110)
Select * from Batch where      
CONVERT(VARCHAR(10),openingtime,110)<>CONVERT(VARCHAR(10),closingtime,110)

**There will be a closing bracket** @Miyamoto Musashi

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM