简体   繁体   English

SQL Server DateAdd不显示查询

[英]Sql Server DateAdd Does not Display Query

I have a query that's suppose to select one of my column if the date inside the column is not expired (the date expires after one hour, see query below). 我有一个查询,如果该列中的日期未过期(该日期在一小时后过期,请参阅下面的查询),我想选择我的一列。 So here is my query and my display with the opposite condition (The field timeForgot is underlined in red, but that seem to be functional) : 所以这是我的查询和条件相反的显示(字段timeForgot用红色下划线标出,但似乎可以正常工作):

查询相反的条件

select DATEADD(HOUR, 2, timeForgot) as Expiration, timeForgot as ReceivedAt, CURRENT_TIMESTAMP as Now
from forgot_password
where DATEADD(HOUR, 2, timeForgot) > Convert(smalldatetime,timeForgot)

But when I apply the right condition, the output show nothing even it should display some fields. 但是,当我应用正确的条件时,即使显示应该显示某些字段,输出也不会显示任何内容。 Could anyone tell me what's wrong with this query? 谁能告诉我此查询出了什么问题?

查询条件正确但无输出

select DATEADD(HOUR, 2, timeForgot) as Expiration, timeForgot as ReceivedAt, CURRENT_TIMESTAMP as Now
from forgot_password
where DATEADD(HOUR, 2, timeForgot) < Convert(smalldatetime,timeForgot)

The reason is simple this 原因很简单

 DATEADD(HOUR, 2, timeForgot) < Convert(smalldatetime,timeForgot)

Is never true. 从来都不是真的。

What exactly did you expect this line to filter out? 您究竟希望该行过滤掉什么?

Maybe you mean 也许你是说

DATEADD(HOUR, 2, timeForgot) > Convert(smalldatetime,timeForgot)

That would be similar to your first query. 那将类似于您的第一个查询。

Sorry for bothering you, I've found my answer, It was kind of a mess in my head, the query that I did want to achieve was this one : 对不起,打扰您了,我找到了答案,这真是一团糟,我确实想要实现的查询就是:


    select DATEADD(HOUR, 2, timeForgot) as Expiration, timeForgot as ReceivedAt, CURRENT_TIMESTAMP as Now
from forgot_password
where DATEADD(MINUTE, 5, timeForgot) > CURRENT_TIMESTAMP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM