sql动态日期比较 [英] sql dynamic date comparison
问题描述
在我的数据库中,我有两列(获得)用于设置首次输入条目的日期( 2012-08-03 14:18:39
)。第二列(已处理)设置处理该条目的日期。我想要一个查询来查找数据库中的条目,而在获取和处理条目之间已经过了两天的时间。
In my database I have two columns one (Obtained) sets a date (2012-08-03 14:18:39
) when an entry is first made. The second column (Processed) sets a date when that entry is processed. I would like a query that looks for entries in the database where over two days’ time have passed between obtaining and processing of the entries.
可能吗?
推荐答案
与答案相反建议 DATEDIFF( )
,仅使用时间戳的 DATE
部分, TIMESTAMPDIFF()
可让您返回记录,该记录位于至少已经整整两天(即48小时)过去了:
In contrast with the answers that suggest DATEDIFF()
, which only uses the DATE
part of your timestamps, TIMESTAMPDIFF()
enables you to return records where at least two full days (i.e. 48 hours) have elapsed:
SELECT * FROM myTable WHERE TIMESTAMPDIFF(DAY, Obtained, Processed) >= 2
这篇关于sql动态日期比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!