SQL 显示日期大于当前日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6678560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 11:19:02  来源:igfitidea点击:

showing that a date is greater than current date

sqlsql-servertsql

提问by GabrielVa

How would I show something in SQL where the date is greater than the current date?

如何在 SQL 中显示日期大于当前日期的内容?

I want to pull out data that shows everything greater from today (now) for the next coming 90 days.

我想提取显示从今天(现在)到未来 90 天的所有内容的数据。

I was thinking =< {fn NOW()}but that doesnt seem to work in my sql view here.

我在想,=< {fn NOW()}但这在我的 sql 视图中似乎不起作用。

How can this be done?

如何才能做到这一点?

回答by Massimiliano Peluso

SELECT * 
FROM MyTable 
WHERE CreatedDate >= getdate() 
AND CreatedDate <= dateadd(day, 90, getdate())

http://msdn.microsoft.com/en-us/library/ms186819.aspx

http://msdn.microsoft.com/en-us/library/ms186819.aspx

回答by Nick Brekalo

Assuming you have a field for DateTime, you could have your query look like this:

假设你有一个字段DateTime,你可以让你的查询看起来像这样:

SELECT *
FROM TABLE
WHERE DateTime > (GetDate() + 90)

回答by Jamie M.

For those that want a nice conditional:

对于那些想要一个好的条件:

DECLARE @MyDate DATETIME  = 'some date in future' --example  DateAdd(day,5,GetDate())

IF @MyDate < DATEADD(DAY,1,GETDATE())
    BEGIN
        PRINT 'Date NOT greater than today...'
END
ELSE 
    BEGIN
       PRINT 'Date greater than today...'
END 

回答by ysrb

In sql server, you can do

在sql server中,你可以做

SELECT *
FROM table t
WHERE t.date > DATEADD(dd,90,now())

回答by Mikael Eriksson

For SQL Server

对于 SQL Server

select *
from YourTable
where DateCol between getdate() and dateadd(d, 90, getdate())

回答by JMoen

Select * from table where date > 'Today's date(mm/dd/yyyy)'

You can also add time in the single quotes(00:00:00AM)

您还可以在单​​引号中添加时间(00:00:00AM)

For example:

例如:

Select * from Receipts where Sales_date > '08/28/2014 11:59:59PM'

回答by David

If you're using SQL Server it would be something like this:

如果您使用的是 SQL Server,它将是这样的:

DATEDIFF(d,GETDATE(),FUTUREDATE) BETWEEN 0 AND 90